android系统的AlertDialog.Builder 只有标题,信息,按钮。
如果我们想制作一个带输入框的对话框,需要我们自定义一个对话框。
1 设置我们对话框的布局文件
2 将布局文件设置到AlertDialog中
3 显示我们的对话框
3 显示我们的对话框
如果我们想制作一个带输入框的对话框,需要我们自定义一个对话框。
1 设置我们对话框的布局文件
2 将布局文件设置到AlertDialog中
3 显示我们的对话框
----------------------------------------------------------
1 设置我们对话框的布局文件
效果图:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dip"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="55dip"
android:background="#66ff6600"
android:gravity="center"
android:text="设置密码"
android:textSize="30sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="55dip"
android:hint="请输入密码"
android:inputType="textPassword" />
<EditText
android:layout_width="match_parent"
android:layout_height="55dip"
android:hint="请再次输入密码"
android:inputType="textPassword" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:layout_width="150dip"
android:layout_height="wrap_content"
android:text="确定" />
<Button
android:layout_width="150dip"
android:layout_height="wrap_content"
android:text="取消" />
</LinearLayout>
</LinearLayout>
3 显示我们的对话框
/**
* 设置密码对话框
*/
private void showSetupPwdDialog() {
AlertDialog.Builder builder =new Builder(HomeActivity.this);
//自定义一个布局文件
View view =View.inflate(HomeActivity.this, R.layout.dialog_setup_pwd, null);
builder.setView(view);
builder.show();
}