【起航计划 005】2015 起航计划 Android APIDemo的魔鬼步伐 04 App->Activity->Custom Dialog Dialog形式的Activity,Theme的使用,Shape的使用
2015-03-02 09:52
645 查看
App->Activity->Custom Dialog 例子使用Activity 来实现自定义对话框
类CustomDialogActivity本身无任何特别之处。关键的一点是其在AndroidManifest.xml中的定义:
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属性,使用了褐色背景。
类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>
![](http://www.imobilebbs.com/wordpress/wp-content/uploads/2011/04/20110430001.png)
相关文章推荐
- 【起航计划 005】2015 起航计划 Android APIDemo的魔鬼步伐 04 App-&gt;Activity-&gt;Custom Dialog Dialog形式的Activity,Theme的使用,Shape的使用
- 【起航计划 013】2015 起航计划 Android APIDemo的魔鬼步伐 12 App->Activity->SetWallpaper 设置壁纸 WallpaperManager getDrawingCache使用
- 【起航计划 009】2015 起航计划 Android APIDemo的魔鬼步伐 08 App->Activity->QuickContactsDemo 联系人 ResourceCursorAdapter使用 QuickContactBadge使用
- 【起航计划 006】2015 起航计划 Android APIDemo的魔鬼步伐 05 App->Activity->Custom Title 自定义标题栏
- 【起航计划 013】2015 起航计划 Android APIDemo的魔鬼步伐 12 App-&gt;Activity-&gt;SetWallpaper 设置壁纸 WallpaperManager getDrawingCache使用
- 【起航计划 009】2015 起航计划 Android APIDemo的魔鬼步伐 08 App-&gt;Activity-&gt;QuickContactsDemo 联系人 ResourceCursorAdapter使用 QuickContactBad
- 【起航计划 006】2015 起航计划 Android APIDemo的魔鬼步伐 05 App-&gt;Activity-&gt;Custom Title 自定义标题栏
- 【起航计划 019】2015 起航计划 Android APIDemo的魔鬼步伐 18 App->Device Admin 设备管理器 DeviceAdminReceiver DevicePolicyManager PreferenceActivity的使用
- 【起航计划 004】2015 起航计划 Android APIDemo的魔鬼步伐 03 App->Activity->Animation Activity跳转动画 R.anim.×× overridePendingTransition ActivityOptions类
- 【起航计划 014】2015 起航计划 Android APIDemo的魔鬼步伐 13 App->Activity->Translucent 半透明Activity Theme.Translucent
- 【起航计划 010】2015 起航计划 Android APIDemo的魔鬼步伐 09 App-&gt;Activity-&gt;Redirection 根据shared preferences是否有值决定是否redirect
- 【起航计划 023】2015 起航计划 Android APIDemo的魔鬼步伐 22 App->Menu->Inflate from XML 使用xml资源展示菜单
- 【起航计划 011】2015 起航计划 Android APIDemo的魔鬼步伐 10 App-&gt;Activity-&gt;Reorder Activities 后退栈 Intent FLAG
- 【起航计划 008】2015 起航计划 Android APIDemo的魔鬼步伐 07 App->Activity->Persistent State 保存状态 SharedPreferences onPause onResume
- 【起航计划 014】2015 起航计划 Android APIDemo的魔鬼步伐 13 App-&gt;Activity-&gt;Translucent 半透明Activity Theme.Translucent
- 【起航计划 028】2015 起航计划 Android APIDemo的魔鬼步伐 27 App->Preferences->Launching preferences 其他activity获取Preference中的值
- 【起航计划 022】2015 起航计划 Android APIDemo的魔鬼步伐 21 App->Launcher Shortcuts 为某个非主Activity在Home Screen上建立一个快捷方式
- 【起航计划 016】2015 起航计划 Android APIDemo的魔鬼步伐 15 App->Activity->Wallpaper 系统壁纸作为当前Activity的背景
- 【起航计划 011】2015 起航计划 Android APIDemo的魔鬼步伐 10 App->Activity->Reorder Activities 后退栈 Intent FLAG
- 【起航计划 012】2015 起航计划 Android APIDemo的魔鬼步伐 11 App-&gt;Activity-&gt;Save &amp; Restore State onSaveInstanceState onRestoreInstance