我的Android進階之旅------>怎樣將Activity變為半透明的對話框?



             

我的Android進階之旅------>怎樣將Activity變為半透明的對話框?能夠從兩個方面來考慮:對話框和半透明。

在定義Activity時指定Theme.Dialog主題就能夠將Activity設置為對話框風格。

通過改動Theme.Dialog主題的android:windowBackground屬性值能夠改變Activity的背景圖像。

假設背景圖像使用半透明的圖像,則Activity就好變成半透明的對話框。為了改動android:windowBackground屬性,能夠定義一個新的主題,該主體繼承自Theme.Dialog,代碼例如以下:

在res/values下創建兩個xml文件。一個為主題風格資源dialog_styles.xml。

一個為顏色資源dialog_colors.xml。


dialog_styles.xml,主題風格名為  dialog_translucent

<?xml version="1.0" encoding="utf-8"?

> <resources> <style name="dialog_translucent" parent="@android:style/Theme.Dialog"> <item name="android:windowBackground">@color/translucent_background</item> <item name="android:windowIsTranslucent">true</item> <item name="android:windowNoTitle">true</item> <item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item<span style="white-space:pre"> </span>> </style> </resources>

dialog_colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name = "translucent_background">#00000000</color>
</resources>

在AndroidManifest.xml為Activity指定自己定義的主題, android:theme="@style/dialog_translucent" 

代碼例如以下:

       <activity
            android:name=".DialogActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/dialog_translucent" ><!-- 引用自己定義的主題 -->>
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>



==================================================================================================

  作者:歐陽鵬  歡迎轉載,與人分享是進步的源泉!

  轉載請保留原文地址http://blog.csdn.net/ouyang_peng

==================================================================================================

  



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM