100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > android activity透明主题 Android应用的全透明效果--Activity及Dialog的全透明

android activity透明主题 Android应用的全透明效果--Activity及Dialog的全透明

时间:2022-12-01 09:06:44

相关推荐

android activity透明主题 Android应用的全透明效果--Activity及Dialog的全透明

1.Activity全透明

同学给了这个有趣的代码,现在公布出来。

先在res/values下建colors.xml文件,写入:<?xmlversion ="1.0"encoding="UTF-8"?>

#9000

这个值设定了整个界面的透明度,为了看得见效果,现在设为透明度为56%(9/16)左右。

再在res/values/下建styles.xml,设置程序的风格<?xml version="1.0" encoding="utf-8"?>

@color/transparent

true

@+android:style/Animation.Translucent

最后一步,把这个styles.xml用在相应的Activity上。即在AndroidManifest.xml中的任意标签中添加android:theme = "@style/transparent"

如果想设置所有的activity都使用这个风格,可以把这句标签语句添加在中。

最后运行程序,是不是发现整个界面都被蒙上一层半透明了。最后可以把背景色#9000换成#0000,运行程序后,就全透明了,看得见背景下的所有东西可以却都操作无效。很有趣吧。。。

2.Dialog全透明

1.准备保留边框的全透明素材如下图:

2.在values中新建一styles.xml文件,内容如下:<?xml version="1.0" encoding="UTF-8"?>

@drawable/panel_background_sodino1

false

@style/TitleStyle

@style/TitleText

#000

3.在layout文件夹下新建一文件句为main_dialog.xml,内容如下:<?xml version="1.0" encoding="UTF-8"?>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#0000">

android:layout_width="wrap_content"

android:layout_height="200px"

android:layout_below="@+id/ImageView01"

android:background="#0000">

android:text="SodinoText"

android:textColor="#f000"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#0000"

>

android:layout_below="@id/ScrollView01"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:text="Cancel">

4.Activity代码如下:package lab.sodino.tanc;

import android.app.Activity;

import android.app.Dialog;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.TextView;

public class TANCAct extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button btnShow = (Button) findViewById(R.id.btnShow);

btnShow.setOnClickListener(new Button.OnClickListener() {

public void onClick(View view) {

showTANC(

"This is my custom dialog box",

"TextContent/nWhen a dialog is requested for the first time, Android calls onCreateDialog(int) from your Activity, which is where you should instantiate the Dialog. This callback method is passed the same ID that you passed to showDialog(int). After you create the Dialog, return the object at the end of the method.",

"/sodino");

}

});

}

private void showTANC(String header, String content, String url) {

final Dialog dialog = new Dialog(this, R.style.TANCStyle);

dialog.setContentView(R.layout.main_dialog);

dialog.setTitle(header);

dialog.setCancelable(true);

TextView textView01 = (TextView) dialog.findViewById(R.id.TextView01);

textView01.setText(content + content + content);

Button btnCancel = (Button) dialog.findViewById(R.id.btnCancel);

btnCancel.setOnClickListener(new Button.OnClickListener() {

public void onClick(View view) {

dialog.cancel();

}

});

dialog.show();

}

}

最后效果图:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。