Android手机开发:Dialog的使用
2011-08-09 19:43
423 查看
1. 只含有OK和Cancel按钮的Dialog
2. 含有3个按钮的Dialog
3. 包含OK和Cancel按钮,以及一个View的Dialog
R.layout.alert_dialog_text_entry定义如下:
4. 直接使用ProgressDialog
private Dialog buildDialog1(Context context) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setIcon(R.drawable.alert_dialog_icon); builder.setTitle(R.string.alert_dialog_two_buttons_title); builder.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { setTitle("点击了对话框上的确定按钮"); } }); builder.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { setTitle("点击了对话框上的取消按钮"); } }); return builder.create(); }
2. 含有3个按钮的Dialog
private Dialog buildDialog2(Context context) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setIcon(R.drawable.alert_dialog_icon); builder.setTitle(R.string.alert_dialog_two_buttons_msg); builder.setMessage(R.string.alert_dialog_two_buttons2_msg); builder.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { setTitle("点击了对话框上的确定按钮"); } }); builder.setNeutralButton(R.string.alert_dialog_something, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { setTitle("点击了对话框上的进入详细按钮"); } }); builder.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { setTitle("点击了对话框上的取消按钮"); } }); return builder.create(); }
3. 包含OK和Cancel按钮,以及一个View的Dialog
private Dialog buildDialog3(Context context) { LayoutInflater inflater = LayoutInflater.from(this); final View textEntryView = inflater.inflate( R.layout.alert_dialog_text_entry, null); AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setIcon(R.drawable.alert_dialog_icon); builder.setTitle(R.string.alert_dialog_text_entry); builder.setView(textEntryView); builder.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { setTitle("点击了对话框上的确定按钮"); } }); builder.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { setTitle("点击了对话框上的取消按钮"); } }); return builder.create(); }
R.layout.alert_dialog_text_entry定义如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/username_view" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:text="用户名" android:textAppearance="?android:attr/textAppearanceMedium" /> <EditText android:id="@+id/username_edit" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:capitalize="none" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/password_view" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:text="密码" android:textAppearance="?android:attr/textAppearanceMedium" /> <EditText android:id="@+id/password_edit" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:capitalize="none" android:password="true" android:textAppearance="?android:attr/textAppearanceMedium" /> </LinearLayout>
4. 直接使用ProgressDialog
private Dialog buildDialog4(Context context) { ProgressDialog dialog = new ProgressDialog(context); dialog.setTitle("正在下载歌曲"); dialog.setMessage("请稍候……"); return dialog; }
相关文章推荐
- Android开发中Dialog对话框的使用
- Android开发中Dialog对话框的使用
- Android 开发之Dialog中隐藏键盘的正确使用方法
- Android开发之listView使用(手机应用列表显示)
- 使用Python开发Android应用程序:第一节 在手机上配置Python运行环境
- 使用Python开发Android应用程序:第三节 在电脑上编写程序在手机上运行
- android开发小技巧(3)dialog自定义弹出框的使用
- android开发中-使用Dialog prompt获取输入信息
- 【Android开发】Dialog的使用
- Android开发小知识-TimePickerDialog和DatePickerDialog的使用
- android开发之DatePickerDialog与TimePickerDialog的使用
- Android开发之控制手机振动(Vibrator的使用)
- Android开发中Dialog对话框的使用
- Android开发笔记之:Dialog的使用详解
- Android开发中Dialog对话框的使用
- Android开发之Dialog使用
- Android初级开发(八)——手机多媒体—通知的使用
- Android开发中Dialog对话框的使用
- 使用Python开发Android应用程序:第三节 在电脑上编写程序在手机上运行