標籤:
android設定背景色為透明
方法一:
只要在設定檔內activity屬性配置內加上
android:theme="@android:style/Theme.Translucent"
就好了。
這樣就調用了android的透明樣式!
方法二:
先在res/values下建colors.xml檔案,寫入:
<?xmlversion="1.0"encoding="UTF-8"?> <resources> <colorname="transparent">#9000</color> </resources>
這個值設定了整個介面的透明度,為了看得見效果,現在設為透明度為56%(9/16)左右。
再在res/values/下建styles.xml,設定程式的風格
<?xmlversion="1.0"encoding="utf-8"?> <resources> <style name="Transparent"> <item name="android:windowBackground">@color/transparent</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item> </style> </resources>
最後一步,把這個styles.xml用在相應的Activity上。即在AndroidManifest.xml中的任意<activity>標籤中添加
android:theme="@style/transparent"
如果想設定所有的activity都使用這個風格,可以把這句標籤語句添加在<application>中。
最後運行程式,是不是發現整個介面都被蒙上一層半透明了。最後可以把背景色#9000換成#0000,運行程式後,就全透明了,看得見背景下的所有東西可以卻都操作無效。
android設定Activity背景色為透明的2種方法