zoukankan      html  css  js  c++  java
  • AlertDialog 自定义View

        

    首先我们定义一个界面

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="10dp">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/title"
            android:scaleType="fitXY"/>
        <EditText
            android:id="@+id/nameET"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="用户名"/>
        <EditText
            android:id="@+id/pwdET"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="密码"/>
    
    </LinearLayout>
    custom_dialog.xml

    放在这

                 

    然后我们加载布局文件就可以了

    //新建一个view
    View customView = View.inflate(this,R.layout.custom_dialog,null);
    //获取view的内容
    final EditText nameET = customView.findViewById(R.id.nameET);
    final EditText pwdET = customView.findViewById(R.id.pwdET);
    //展示对话框
    new AlertDialog.Builder(this)
            .setView(customView)
            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String name = nameET.getText().toString();
                    String pwd = pwdET.getText().toString();
                    String msg = name+" "+pwd;
                    System.out.println(msg);
                    Toast.makeText(MainActivity.this,msg,Toast.LENGTH_SHORT).show();
                }
            })
            .setNegativeButton("取消",null)
            .show();
    自定义对话框
  • 相关阅读:
    rocketmq手工创建topic出错
    rocketmq
    redis基本操作命令key命令+string命令+事务操作命令
    Redis启动常用管理命令
    --环比去年,row_number() over()取最新版本
    二分查找
    使用Python实现的4种快速排序算法
    卷积神经网络的理解
    两个很赞的用法(count函数里的表达式+计算时间间隔)
    MySQL中exists和in的区别及使用场景
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/12728132.html
Copyright © 2011-2022 走看看