Android設定Activity背景為透明style
阿新 • • 發佈:2019-02-03
方法一:
通過Theme.Translucent
@android:style/Theme.Translucent
@android:style/Theme.Translucent.NoTitleBar
@android:style/Theme.Translucent.NoTitleBar.Fullscreen
只需要在Manifest中需要透明的Activity內設定theme為以上任意一個就可以了
<activity android:name="com.vixtel.simulate.MainApp" android:configChanges="keyboardHidden|orientation" android:label="@string/app_name" android:screenOrientation="portrait" android:theme="@android:style/Theme.Translucent.NoTitleBar" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
方法二:
自定義style,就像自定義Dialog的style一樣,在res-values-color.xml中新增透明顏色值:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<color name="transparent">#0000</color>
</resources>
在res-values-styles.xml中新增如下:
<style name="myTransparent"> <item name="android:windowBackground">@color/transparent</item> <item name="android:windowNoTitle">true</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item> </style>
在Manifest中中需要透明的Activity內設定theme為我們自定義的即可
android:theme="@style/myTransparent"
執行程式後,就全透明瞭,看得見背景下的所有東西可以卻都操作無效。