当前位置:操作系统 > 安卓/Android >>

Android对话框

1. 普通对话框
 
 \


[java] AlertDialog.Builder builder = new Builder(GenContextMenu.this); 
        builder.setTitle("标题"); 
        builder.setPositiveButton("确定", null); 
        builder.setIcon(android.R.drawable.ic_dialog_info); 
        builder.setMessage("简单消息框"); 
        builder.show(); 
AlertDialog.Builder builder = new Builder(GenContextMenu.this);
  builder.setTitle("标题");
  builder.setPositiveButton("确定", null);
  builder.setIcon(android.R.drawable.ic_dialog_info);
  builder.setMessage("简单消息框");
  builder.show();

2. 确定取消对话框
  \


AlertDialog.Builder builder = new Builder(GenContextMenu.this);  
        builder.setTitle("标题");  
        builder.setPositiveButton("确定",null);  
        builder.setNegativeButton("取消",null);  
        builder.setIcon(android.R.drawable.ic_dialog_info);  
        builder.setMessage("简单消息框");  
        builder.show(); 
AlertDialog.Builder builder = new Builder(GenContextMenu.this);
  builder.setTitle("标题");
  builder.setPositiveButton("确定",null);
  builder.setNegativeButton("取消",null);
  builder.setIcon(android.R.drawable.ic_dialog_info);
  builder.setMessage("简单消息框");
  builder.show();
3. 提示输入对话框
 
 \


 

AlertDialog.Builder builder = new Builder(GenContextMenu.this);  
        builder.setTitle("标题");  
        builder.setView(new EditText(GenContextMenu.this));  
        builder.setPositiveButton("确定",null);  
        builder.setNegativeButton("取消",null);  
        builder.setIcon(android.R.drawable.ic_dialog_info);  
        builder.setMessage("简单消息框");  
        builder.show();  
AlertDialog.Builder builder = new Builder(GenContextMenu.this);
  builder.setTitle("标题");
  builder.setView(new EditText(GenContextMenu.this));
  builder.setPositiveButton("确定",null);
  builder.setNegativeButton("取消",null);
  builder.setIcon(android.R.drawable.ic_dialog_info);
  builder.setMessage("简单消息框");
  builder.show();

4. 带有单选择按钮的对话框
  \


 

new AlertDialog.Builder(GenContextMenu.this)  
        .setTitle("请选择")  
        .setIcon(android.R.drawable.ic_dialog_info)  
        .setSingleChoiceItems(new String[] {"item1","item2","item3","item4"}, 0,  
            new DialogInte易做图ce.OnClickListener(){  
                public void onClick(DialogInte易做图ce dialog, int which){  
                dialog.dismiss();  
                }  
            }  
        )  
        .setNegativeButton("取消", null)  
        .show();  
new AlertDialog.Builder(GenContextMenu.this)
  .setTitle("请选择")
  .setIcon(android.R.drawable.ic_dialog_info)
  .setSingleChoiceItems(new String[] {"item1","item2","item3","item4"}, 0,
      new DialogInte易做图ce.OnClickListener(){
          public void onClick(DialogInte易做图ce dialog, int which){
          dialog.dismiss();
          }
      }
  )
  .setNegativeButton("取消", null)
  .show();

5. 带有多选择按钮的对话框
  \


 

new AlertDialog.Builder(GenContextMenu.this)  
        .setTitle("请选择")  
        .setIcon(android.R.drawable.ic_dialog_info)  
        .setMultiChoiceItems(new String[] {"item1","item2","item3","item4"}, null, null)  
        .setNegativeButton("取消", null)  
        .show();  
new AlertDialog.Builder(GenContextMenu.this)
  .setTitle("请选择")
  .setIcon(android.R.drawable.ic_dialog_info)
  .setMultiChoiceItems(new String[] {"item1","item2","item3","item4"}, null, null)
  .setNegativeButton("取消", null)
  .show();

 

摘自  Snowball
 
补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,