1.Demo說明與示範
該Demo顯示一個半透明Activity,主要是通過Style和Theme來實現的
如下:
2.視頻講解
http://www.eyeandroid.com/thread-10936-1-1.html
3.Demo分析
Activity分類樣本的最後幾個例子是來顯示半透明Activity。例子大同小異。實現Activity的半透明效果主要是通過Style和Theme來實現的。
看看TranslucentActivity 在AndroidManifest.xml中的定義:
<activity android:name=”.app.TranslucentActivity”
android:label=”@string/activity_translucent”
android:theme=”@style/Theme.Translucent”>
<intent-filter>
< action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.SAMPLE_CODE” />
< /intent-filter>
< /activity>
它使用了Theme.Translucent 主題,這個主題定義在res/styles.xml
<!– A theme that has a translucent background. Here we explicitly specify
that this theme is to inherit from the system’s translucent theme,
which sets up various attributes correctly. –>
<style name=”Theme.Translucent” parent=”android:style/Theme.Translucent”>
<item name=”android:windowBackground”>@drawable/translucent_background</item>
< item name=”android:windowNoTitle”>true</item>
< item name=”android:colorForeground”>#fff</item>
< /style>
它通過繼承系統主題android:style/Theme.Translucent,然後加以修改。@drawable/translucent_background定義在Colors.xml中,顏色值為#e0000000 ,alpha值,也就是透明度為#e0(半透明)。