android 弹出输入框
时间: 2023-06-30 13:11:02 浏览: 179
要在 Android 中弹出输入框,可以使用以下代码:
```
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Title");
// Set up the input
final EditText input = new EditText(this);
// Specify the type of input expected; this sets the input type to a text field.
input.setInputType(InputType.TYPE_CLASS_TEXT);
builder.setView(input);
// Set up the buttons
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String text = input.getText().toString();
// Do something with the text entered by the user
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
```
这个代码会弹出一个对话框,其中有一个文本输入框和“OK”和“Cancel”两个按钮,用户可以在文本框中输入文本,然后点击“OK”按钮来保存文本,或者点击“Cancel”按钮来取消操作。
阅读全文
相关推荐
















