使用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>中。