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();
    自定义对话框
  • 相关阅读:
    CSS font-family 字体名称一览表
    jQuery动态追加移除CSS样式
    Java中super关键字的作用与用法
    I Have a Dream(我有一个梦想)
    再读《诫子书》
    世间谤我、欺我、辱我、笑我,为之奈何?
    英语句型:我除了音乐一无所能
    H5 iphoneX适配方案
    对象序列化成字符串,拼接在请求url后面
    React 60s倒计时
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/12728132.html
Copyright © 2011-2022 走看看