展会信息港展会大全

Android:将activity设置为弹出式的并设置为透明的
来源:互联网   发布日期:2016-01-14 10:42:55   浏览:3139次  

导读:1. 在res/values 下建立color.xml<resources> <color name="transparent_background">#80ffffff</color...

1. 在res/values 下建立color.xml

<resources><color name="transparent_background">#80ffffff</color>

</resources>PS: #80是透明度的值(即80%透明),ffffff是颜色值(为黑色)

2. 在res/values下建立style.xml

<resources> <style name="Transparent" parent="android:style/Theme.Dialog"><item name="android:windowBackground">@color/transparent_background</item><item name="android:windowNoTitle">true</item><item name="android:windowIsTranslucent">true</item><item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item> </style></resources>PS: parent="android:style/Theme.Dialog" 是将activity设置为弹出式窗口

3. 在AndroidManifest.xml中找到要弹出的activity,加入theme:

<activity android:name="ActivityName"android:theme="@style/Transparent"/>完成上面设置后,你的activity就已经是透明的了,但是该Activity中的控件还没有透明,如果还需要控件透明,则需要在该activity的代码中加入如下代码:

//设置activity中的控件透明Window window = getWindow();WindowManager.LayoutParams wl = window.getAttributes();wl.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;wl.alpha=0.95f;//设置透明度,0.0为完全透明,1.0为完全不透明window.setAttributes(wl);

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港