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

來源:互聯網
上載者:User

標籤:3.3   定義   cti   launch   round   半透明   white   背景圖   art   


             

我的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

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

  

我的Android進階之旅------&gt;怎樣將Activity變為半透明的對話方塊?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.