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.2cto.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="http://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>