Android ApiDemos樣本解析(4) App->Activity->Custom Dialog

來源:互聯網
上載者:User

App->Activity->Custom Dialog 例子使用Activity 來實現自訂對話方塊。 類CustomDialogActivity本身無任何特別 之處。關鍵的一點是其在AndroidManifest.xml中的定義:

<activity android:name=”.app.CustomDialogActivity” android:label=”@string/activity_custom_dialog”android:theme=”@style/Theme.CustomDialog “>

<intent-filter>

< action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.SAMPLE_CODE” />

< /intent-filter>

< /activity>

CustomDialogActivity使用了CustomDialog 風格(Theme)。

Android應用可以使用自訂的介面 風格(Theme),Theme 為一組相關的Style定義,可以應用於某個Activity或是整個Application。使用Theme的一個好處是可以 為整個應用定義統一的介面風格(統一的背景色,字型等)。

定義Theme 和定義Style一樣, 必須定義在/res/values子 目錄下,根項目名為resources, Theme 和Style的區別在於Theme應用於Activity和Application而 Style應用於單個的View。 其定義方法是一致的。Style 定義支援 Inheritance, 也就是在定義新風格時可以基於系統定義的風格或是之前定義的風 格:

如Theme.CustomDialog 定義就是基於Android的Dialog風格(parent)而只修改的WindowsBackground屬性,使用了褐 色背景。

<style name=”Theme.CustomDialog” parent=”android:style/Theme.Dialog”>

<item name= ”android:windowBackground”>@drawable/filled_box</item>

< /style>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.