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" />

运行截图如下:

更多相关文章

  1. Android通过内容提供器获取相册中所有图片
  2. android meta-data获取
  3. 获取Android正在运行的任务和服务
  4. DataBinding(双向绑定)
  5. CCRenderTexture 从后台进入前台变黑的处理(android)
  6. Android获取前台进程包名
  7. 关于android theme
  8. 组件化实践记录——在library module的manifest中使用applicatio
  9. Android(安卓)切换主题 (二)

随机推荐

  1. 多业务融合推荐策略实践与思考
  2. 电商知识图谱
  3. FPGA设计笔记:QSPI Flash与DDR3L SDRAM采
  4. 空间计量各种模型代码笔记分享, 可以直接
  5. 从概念到应用,终于有人把数据挖掘讲明白了
  6. NBER最大规模改版! 超强大的搜索功能和人
  7. Samtec公司推出14Gbps FireFly FMC高速通
  8. 从图灵机、图灵测试到人工智能:什么决定了
  9. 基于Xilinx Zynq Z7045 SoC的CNN的视觉识
  10. 旅行场景下的个性化营销平台揭秘