android 带EditView(编辑框)的AlertDialog(对话框)及获取输入内容
16lz
2021-01-25
首先在XML中设置一个Button来控制弹出框(AlertDialog)
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="弹出对话框" android:onClick="alert_edit"/>
在Activity中添加对应的弹出方法
public void alert_edit(View view){ final EditText et = new EditText(this); new AlertDialog.Builder(this).setTitle("请输入消息") .setIcon(android.R.drawable.sym_def_app_icon) .setView(et) .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { //按下确定键后的事件 Toast.makeText(getApplicationContext(), et.getText().toString(),Toast.LENGTH_LONG).show(); } }).setNegativeButton("取消",null).show(); }
更多相关文章
- Android(安卓)onTouchEvent的MotionEvent.ACTION_UP不响应
- android开发之PreferenceScreen使用详解
- Android实现EventBus登录界面与传值(粘性事件)
- python搭建服务器实现两个Android客户端间收发消息
- android源码分析 - AysncTask
- Android输入设备处理流程
- Android开发艺术探索 - 第10章 Android的消息机制
- Android:消息机制
- Android(安卓)按钮响应点击事件的三种实现方式