如何使用Activity创建对话框
来源:互联网 发布:阿里云 弹性ip bgp带宽 编辑:程序博客网 时间:2024/06/03 16:16
本示例使用Android系统对话框主题样式来创建一个对话框。
1. 定义清单文件(AndroidManifest.xml)
<?xmlversion="1.0"encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="my.android.test"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon"android:label="@string/app_name">
<!-- 给Activity应用系统的对话框样式Theme.Dialog -->
<activity android:name=".DialogActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Dialog">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="9"/>
</manifest>
2. 定义字符串资源(strings.xml)
<?xmlversion="1.0"encoding="utf-8"?>
<resources>
<string name="hello">Hello World, DialogActivity!</string>
<string name="app_name">DialogActivity</string>
<string name="dialog_activity_text">Example of how you can use the
Theme.Dialog theme to make an activity that looks like a
dialog.</string>
</resources>
3. 定义布局文件(dialog_activity.xml)
<?xmlversion="1.0"encoding="utf-8"?>
<!-- 用户显示对话框文本 -->
<TextViewxmlns: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/dialog_activity_text"/>
4. 创建Activity类(DialogActivity.java)
package my.android.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
publicclass DialogActivityextends Activity {
/** Activity被首次创建时,调用该方法 */
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//调用requestWindowFeature()方法启用扩展的窗口特征。
//Window.FEATURE_LEFT_ICON:设置标题栏的左下方的一个图标资源可用。
if(true == requestWindowFeature(Window.FEATURE_LEFT_ICON)){
//填充布局
setContentView(R.layout.dialog_activity);
//给窗口设定描画资源。
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
android.R.drawable.ic_dialog_alert);
}else{
//
}
}
}
- 如何使用Activity创建对话框
- 如何创建和使用无模式对话框
- 如何创建和使用无模式对话框
- Activity如何管理对话框
- 使用对话框弹activity
- 如何创建非模态对话框
- 如何创建非模态对话框?
- 如何使用DialogFragment类来创建和显示对话框
- CFile类使用如何创建文件打开对话框
- VC/MFC如何使用CreateEx()创建自己的对话框资源
- 如何在MFC中创建和使用对话框
- 如何使用Cocos Studio创建对话框,并用Cocos2d-x显示
- 如何使用DialogFragment类来创建和显示对话框
- 使用AlertDialog创建对话框
- 使用AlertDialog创建对话框
- 使用AlertDialog创建对话框
- 使用AlterDialog创建对话框
- 使用Activity实现对话框效果
- UIToolkit for Unity 很不错的UITookKit
- 【筛选法】欧教发糖
- arm-elf和arm-eabi的区别
- 加密算法简介
- MFC的COleDateTime类使用
- 如何使用Activity创建对话框
- jquery json
- GridView导出成Excel(整理)
- automake,autoconf使用详解
- 重要blog关注
- Excel 匯出,服務器文件資料下載
- VC操作Excel,使用Worksheet的get_Range发生异常
- 利用DB_LINK在不同平台的数据库中复制数据。
- 通过System.getProperties()获取系统参数