【起航計劃 005】2015 起航計劃 Android APIDemo的魔鬼步伐 04 App->Activity->Custom Dialog Dialog形式的Activity,Theme的使用,Shape的使用

來源:互聯網
上載者: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屬性,使用了褐色背景。

    <!-- A theme for a custom dialog appearance.  Here we use an ugly         custom frame. -->    <style name="Theme.CustomDialog" parent="android:style/Theme.Dialog">        <item name="android:windowBackground">@drawable/filled_box</item>    </style>
背景使用了shape,filled_box.xml如下:
<shape xmlns:android="http://schemas.android.com/apk/res/android">    <solid android:color="#f0600000"/>    <stroke android:width="3dp" android:color="#ffff8080"/>    <corners android:radius="3dp" />    <padding android:left="10dp" android:top="10dp"        android:right="10dp" android:bottom="10dp" /></shape>

 

 

 

【起航計劃 005】2015 起航計劃 Android APIDemo的魔鬼步伐 04 App->Activity->Custom Dialog Dialog形式的Activity,Theme的使用,Shape的使用

聯繫我們

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