Activity半透明效果
Android中实现前台Activity的半透明效果。
package com.xiaochun91103; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class TranslucentTest extends Activity { /** Called when the activity is first created. */ private Button bt; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bt = (Button)findViewById(R.id.bt); bt.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(TranslucentTest.this,show.class); startActivity(intent); } }); } }
在点击Button之后,弹出前台Activity为半透明的。
package com.xiaochun91103; import android.app.Activity; import android.os.Bundle; public class show extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.show); } }
在此App种需要声明前台Activity的主题为半透明:
styles.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <mce:style name="Theme.Translucent" parent="android:style/Theme.Translucent"><!-- <item name="android:windowNoTitle">true</item> <item name="android:colorForeground">#fff</item> --></mce:style><style name="Theme.Translucent" parent="android:style/Theme.Translucent" mce_bogus="1"> <item name="android:windowNoTitle">true</item> <item name="android:colorForeground">#fff</item> </style> </resources>
重点是在Manifest文件下声明Activity时,指定Activity的主题
<activity android:name=".show" android:theme="@style/Theme.Translucent" />
运行截图如下:
更多相关文章
- Android通过内容提供器获取相册中所有图片
- android meta-data获取
- 获取Android正在运行的任务和服务
- DataBinding(双向绑定)
- CCRenderTexture 从后台进入前台变黑的处理(android)
- Android获取前台进程包名
- 关于android theme
- 组件化实践记录——在library module的manifest中使用applicatio
- Android(安卓)切换主题 (二)