AlertDialog的用法
来源:互联网 发布:linux下安装python 编辑:程序博客网 时间:2024/05/16 13:04
AlertDialog可以在当前的界面弹出一个对话框,这个对话框是置顶于所有界面元素之上的,能够屏蔽掉其它控件的交互能力。因此,AlertDialog一般都是用于提示一些非常重要的内容或者警告信息。比如,为了防止用户误删重要内容,在删除前弹出一个确认对话框。
MainActivity中的代码:
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn = (Button) findViewById(R.id.id_btn); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this); dialog.setTitle("标题"); dialog.setMessage("内容"); dialog.setCancelable(false); // 可否取消 dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this, "点击了确定", Toast.LENGTH_SHORT).show(); } }); dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); dialog.show(); // 显示对话框 } }); }}
0 0
- Android--AlertDialog的用法
- AlertDialog的各种用法
- AlertDialog的用法
- AlertDialog的用法
- AlertDialog的用法
- AlertDialog的用法
- 关于AlertDialog 的一些用法
- AlertDialog的几种用法
- AlertDialog 的简单用法效果图
- Alertdialog的几种用法
- AlertDialog的几种用法
- AlertDialog的超简单用法
- Android 的 AlertDialog 用法详解
- Android AlertDialog的基本用法
- AlertDialog用法
- 关于Android AlertDialog.builder的用法
- AlertDialog.Builder对话框类的用法
- AlertDialog.Builder对话框类的用法
- B树,B+树,B-树,B*树
- zeppelin源码分析(3)——主要的class分析(中)
- NSLog重定向
- Windows系统安装Pcapy模块
- Ajax的跨域请求问题
- AlertDialog的用法
- jdbc 基础
- F
- Commons IO -- IOUtils
- 阿里云CentOS7.2把默认语言修改成中文
- Android拨号
- Android 性能优化典范
- 阿里图标库的使用
- Python 获取本地时间戳(包含毫秒)