zoukankan      html  css  js  c++  java
  • android中常用的弹出提示框

    首先是一个最简单的应用,就是弹出一个消息框,在android中可以这样实现

        new AlertDialog.Builder(self)
    
        .setTitle("标题" )
    
        .setMessage("简单消息框" )
    
        .setPositiveButton("确定" , null )
    
        .show(); 

    效果如下:

    1.png

    -------------

    下面是带确认和取消按钮的对话框

        new AlertDialog.Builder(self)
        .setTitle("确认" )
        .setMessage("确定吗?" )
        .setPositiveButton("是" , null )
        .setNegativeButton("否" , null)
        .show(); 

    效果如下:

    2.png

    --------------

    下面是一个可以输入文本的对话框

        new AlertDialog.Builder(self)
        .setTitle("请输入" )
        .setIcon(android.R.drawable.ic_dialog_info)
        .setView(new EditText(self))
        .setPositiveButton("确定" , null)
        .setNegativeButton("取消" , null )
        .show(); 

    效果图如下:

    3.png

    ------------

    下面是单选框与多选框,也是非常有用的两种对话框

        new AlertDialog.Builder(self)
        .setTitle("请选择" )
        .setIcon(android.R.drawable.ic_dialog_info)
        .setSingleChoiceItems(new String[] {"选项1", "选项2", "选项3" , "选项4" }, 0 ,
        new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        dialog.dismiss();
        }
        }
        )
        .setNegativeButton("取消" , null )
        .show(); 

    效果图如下:

    4.png

    2.多选框:

    new AlertDialog.Builder(self)
    .setTitle("多选框" )
    .setMultiChoiceItems(new String[] {"选项1", "选项2", "选项3" , "选项4" }, null , null )
    .setPositiveButton("确定" , null)
    .setNegativeButton("取消" , null )
    .show(); 

    多选对话框

    --------------

    列表对话框

        new AlertDialog.Builder(self)
        .setTitle("列表框" )
        .setItems(new String[] {"列表项1", "列表项2", "列表项3" }, null )
        .setNegativeButton("确定" , null )
        .show(); 

    6.png

    --------------------

    在对话框中显示图片:

        ImageView img = new ImageView(self);
        img.setImageResource(R.drawable.icon);
        new AlertDialog.Builder(self)
        .setTitle("图片框" )
        .setView(img)
        .setPositiveButton("确定" , null )
        .show(); 

    7.png

  • 相关阅读:
    java中的常用内存区域总结
    访问权限修饰符-static-final-this-super-匿名对象
    Scanner-String-StringBuilder-API
    This application failed to start because it could not find or load the Qt platform plugin “windows”错误解决方法
    如何优雅的写C++代码(一)
    Color Map的生成方法
    加色法和减色法
    无线电入门书籍推荐
    玩业余无线电的前期准备
    iPhone 上拨号键盘的发音规律
  • 原文地址:https://www.cnblogs.com/vip-ygh/p/3955357.html
Copyright © 2011-2022 走看看