activity以dialog形式顯示

1、AndroidManifest.xml 文件中,申明 activity 的主題使用自定義對話框樣式。   
<activity android:name=".SensorGetValueActivity"  
                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>   
  
  
2、res/values/styles.xml 樣式文件中定義一個對話框主題樣式,這裡繼承瞭 android:style/Theme.Dialog 主題,    www.aiwalls.com
  
並且窗口樣式 android:windowBackground 引用瞭 @drawable/filled_box   
  
<style name="Theme.CustomDialog" parent="android:style/Theme.Dialog">   
    <item name="android:windowBackground">@drawable/filled_box</item>   
</style>   
  
3、res/drawable/filled_box.xml 定義瞭 Shape 類型的 drawable(抽象的可畫區域),最終是通過這個來實現新對話框的樣式。   
<shape xmlns:android="https://schemas.android.com/apk/res/android">   
    <solid android:color="#f0600000"/>   
    <stroke android:width="3dp" color="#ffff8080"/>   
    <corners android:radius="3dp" />   
    <padding android:left="10dp" android:top="10dp"  
        android:right="10dp" android:bottom="10dp" />   
</shape>

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *