Android為透明效果提供了內(nèi)置的主題:Theme(android:style/Theme.Translucent),如果想實現(xiàn)透明效果,只要為Activity設(shè)置該Theme便可。
如果想實現(xiàn)半透明效果,則只需要繼承android:style/Theme.Translucent,并重寫便可。
繼承android:style/Theme.Translucent并重寫:
<?xml version=”1.0″ encoding=”utf-8″?>
<resources>
<style name=”Theme.Translucent” parent=”android:style/Theme.Translucent”>
<item name=”android:windowBackground”>@color/translucent_background</item>
<item name=”android:colorForeground”>#fff</item>
</style>
</resources>
AndroidMainfest.xml中使用該主題:
<activity android:name=”.Translucent”
android:label=”@string/app_name”
android:theme=”@style/Theme.Translucent”
>
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
Eclipse工程:下載
效果圖: