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" />
运行截图如下:
更多相关文章
- GridView 实现水平拖拉效果
- 一个Android实现图片的倒影效果的代码示例
- android 按钮按下效果2
- android实现渐变效果
- android canvas中的save()和restore()的作用及效果
- android仿安卓微信、云播雷达扫描动画效果
- Android为返回键设置动画效果
- Android 模糊效果实现