Android UI学习 - 对话框
来源:互联网 发布:数据挖掘的技术 编辑:程序博客网 时间:2024/05/18 00:56
Android开发指南-用户界面-对话框
Android UI学习 - 对话框
显示对话框
- 注意: 如果你决定在onCreateDialog()方法之外创建一个对话框,它将不会被附着到活动上。不过,你可以通过setOwnerActivity(Activity)把它附着到一个活动上。
- static final int DIALOG_PAUSED_ID = 0;
- static final int DIALOG_GAMEOVER_ID = 1;
- protected Dialog onCreateDialog(int id) {
- Dialog dialog;
- switch(id) {
- case DIALOG_PAUSED_ID:
- // do the work to define the pause Dialog
- break;
- case DIALOG_GAMEOVER_ID:
- // do the work to define the game over Dialog
- break;
- default:
- dialog = null;
- }
- return dialog;
- }
- showDialog(DIALOG_PAUSED_ID);
消除对话框Dismissing a Dialog
使用消除侦听器Using dismiss listeners
- @Override
- protected void onPrepareDialog(int id, Dialog dialog) {
- switch(id){
- case PROGRESS_DIALOG:
- dialog.setOnDismissListener(new DialogInterface.OnDismissListener(){
- @Override
- public void onDismiss(DialogInterface dialog) {
- Toast.makeText(getApplicationContext(),
- "dismiss listener!",
- Toast.LENGTH_SHORT)
- .show();
- }
- });
- }
- }
- //AlertDialog.Builder调用的
- public AlertDialog.Builder setOnCancelListener (DialogInterface.OnCancelListener onCancelListener)
- //Dialog调用的
- public void setOnCancelListener (DialogInterface.OnCancelListener listener)
警告对话框AlertDialog的使用
增加按钮Adding buttons
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setMessage("Are you sure you want to exit?")
- .setCancelable(false)
- .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- MyActivity.this.finish();
- }
- })
- .setNegativeButton("No", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
- }
- });
- AlertDialog alert = builder.create();
增加一个列表Adding a list
- final CharSequence[] items = {"Red", "Green", "Blue"};
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle("Pick a color");
- builder.setItems(items, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int item) {
- Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
- }
- });
- AlertDialog alert = builder.create();
增加复选框和单选按钮
- final CharSequence[] items = {"Red", "Green", "Blue"};
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle("Pick a color");
- builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int item) {
- Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
- }
- });
- AlertDialog alert = builder.create();
进度对话框Progress Dialog的使用
- ProgressDialog.show(this, // context
- "", // title
- "Loading. Please wait...", // message
- true); //进度是否是不确定的,这只和创建进度条有关
显示进度条Showing a progress bar
- ProgressDialog progressDialog = new ProgressDialog(getApplicationContext());
- progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- progressDialog.setIcon(R.drawable.alert_dialog_icon);
- progressDialog.setMessage("Loading...");
- progressDialog.setCancelable(false);
创建自定义对话框Creating a Custom Dialog
0 0
- Android UI学习 - 对话框
- Android UI学习 - 对话框
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android笔记:Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- Android UI对话框找茬
- android ui ->>Dialog对话框
- android UI 组件-对话框
- android UI 对话框大全
- Android学习:用户界面UI之日期和时间对话框
- android ui 学习 之 时间和日期对话框
- WTL 学习(高级对话框UI)
- asm内联汇编及HC08启动代码说明
- Android主题切换方案总结
- ExtJs 4.x 学习小记:Ext.TabPanel滚动条及分页栏不在页面最底端的处理
- va_start和va_end使用详解
- java 接受的网络数不能转换成jsonobject
- Android UI学习 - 对话框
- float与double的范围和精度
- 只要老人想学 社区免费提供电脑
- Unity3d入门教程构建场景 (Building Scenes)>游戏目标 (GameObjects)
- 面向对象的三个基本特征
- 精挑细选 8款HTML5/jQuery应用助网站走向高上大
- c#保留小数点后位数的方法
- Leetcode_binary-tree-postorder-traversal
- 浅谈2014年SEO的发展趋势