Android 2.2 API demos -- Dialog
来源:互联网 发布:广电网络营业厅 编辑:程序博客网 时间:2024/05/17 22:07
在Android中有一种类似于HTML和CSS将样式和内容分离的机制。我们可以将内容定义在layout的XML中,将样式定义在style的XML中。通过HTML和CSS的实践证明,这种分离更有益于代码的重用和维护。
Custom Dialog示例
Android官方API Demo中的Custom Dialog就是一个简单的示例。
首先,将样式(style)定义在res/values/styles.xml中。
Xml代码
<style name="Theme.CustomDialog" parent="android:style/Theme.Dialog"> <item name="android:windowBackground">@drawable/filled_box</item> </style>
其次,将内容(layout)定义在res/layout/custom_dialog_activity.xml中。
Xml代码
<?xml version="1.0" encoding="utf-8"?> <!-- This screen consists of a single text field that displays some text. --> <TextView xmlns:android=http://schemas.android.com/apk/res/android android:id="@+id/text" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_vertical|center_horizontal" android:text="@string/custom_dialog_activity_text"/>
第三,将样式应用到内容上,见AndroidManifest.xml。 将Activity的theme属性配置成想要的style。
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>
在官方的示例中,一个style被应用在一个activity上了,其实一个style还可以被应用在view或者整个application上。如果将一个style应用在activity或者application上,那么这个style就被称作是theme。
- Android 2.2 API demos -- Dialog
- Android API Demos学习 - Dialog部分
- Android 2.2 API demos --- animation
- Android 2.2 API Demos -- ListActivity
- Android 2.2 API Demos -- Service
- Android Api Demos登顶之路(三十七)Fragment-->Dialog
- Android 2.2 API demos -- ApiDemos.java
- Android 2.2 API demos -- theme & style
- Android 2.2 API Demos -- PersistentState(Activity)
- Android 2.2 API Demos -- Intents Chooser
- android Api Demos
- Android API Demos笔记
- Android的API Demos
- Android的API Demos
- android API Demos 路径
- Android Api Demos登顶之路(三十五)Fragment-->Alert Dialog
- Android Api Demos登顶之路(三十八)Fragment-->Dialog or Activity
- Android Api Demos登顶之路(105)View-->Date widgets-->dialog
- HDOJ2006求奇数的成绩
- Java How Program(4th)中的专业词汇ch04
- *getopts的用法*
- log4說明
- C#建立MSSQL数据库本地通用连接
- Android 2.2 API demos -- Dialog
- 将 src中的资源文件自动生成到/web-inf/classes/目录下
- Unix awk 替换域
- 图解-排序(Sort)
- 常用小代碼
- Unix shell和awk 变量交互
- Android学习笔记之滑动翻页(屏幕切换)
- Datatable新增(1)
- xml文件的读写