使用eclipse开发工具,实现xml文件透明十分简单,只要将背景色设置为透明色:“#00000000”即可。
如图:
它 android:background="@color/transparent" 是透明背景色。
但使用IntelliJ IDEA 开发工具,实现xml文件透明就有些麻烦了。
下面是使用IntelliJ IDEA 开发工具,实现xml文件透明具体步骤,在此做一下记录。
直接上代码:
1、在文件 values/colors.xml下创建一个透明颜色值,如下:
<color name="transparent">#00000000</color>
2、在文件 values/styles.xml 下创建一个主题,如下:
<resources>
<style name="Transparent" parent="AppTheme.NoTitleBar">
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item>
</style>
</resources>
3、然后将主题在AndroidManifest.xml中,添加到对应的<activity>标签中,如:
添加:android:theme="@style/transparent"
4、最后在 activity 中的 onCreate 和 setContentView 方法之间添加setTheme(R.style.Transparent),这些工作做完了之后,您就可以在xml布局文件中,任意实现背景色透明度了。
以上介绍的是针对某个activity 实现的背景色透明,如果您想整个App都能 实现背景色透明,那么就将主题设置在<application>中。