android的可输入对话框,android – 用户可以选择输入详细信息或取消的对话框或表单...

该博客介绍了如何通过AlertDialog.Builder在Android应用中创建一个包含自定义布局的警报对话框。首先,利用LayoutInflaterinflate布局文件,然后找到EditText等视图元素,接着设置对话框的正负按钮及点击事件,最后通过Builder创建并显示对话框。
摘要由CSDN通过智能技术生成

您还可以使用AlertDialog.Builder将布局粘贴到警报对话框中,如下所示:

//Preparing views

LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

View layout = inflater.inflate(R.layout.dialog_layout, (ViewGroup) findViewById(R.id.layout_root));

//layout_root should be the name of the "top-level" layout node in the dialog_layout.xml file.

final EditText nameBox = (EditText) layout.findViewById(R.id.name_box);

final EditText phoneBox = (EditText) layout.findViewById(R.id.phone_box);

//Building dialog

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setView(layout);

builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

dialog.dismiss();

//save info where you want it

}

});

builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

dialog.dismiss();

}

});

AlertDialog dialog = builder.create();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值