• AlertDialog自定义


    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="用户名"/>
    
            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
    
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="密码"/>
    
            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
    
        </LinearLayout>
    
    </LinearLayout>
    package com.pingyijinren.helloworld.activity;
    
    import android.content.DialogInterface;
    import android.support.v7.app.AlertDialog;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.view.View;
    import android.widget.Button;
    
    import com.pingyijinren.helloworld.R;
    public class MainActivity extends AppCompatActivity implements View.OnClickListener {
        private AlertDialog alertDialog;
        private Button button;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            button=(Button)findViewById(R.id.button);
            button.setOnClickListener(this);
        }
    
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder=new AlertDialog.Builder(this);
            builder.setIcon(R.mipmap.ic_launcher);
            builder.setTitle("用户登录");
            builder.setView(R.layout.alert_dialog_layout);
            builder.setPositiveButton("退出", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            });
            builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
    
                }
            });
            alertDialog=builder.create();
            alertDialog.show();
        }
    }
  • 相关阅读:
    图解隐马尔科夫模型【会其意】
    基于mysql对mybatis中的foreach进行深入研究
    JS-安全检测JavaScript基本数据类型和内置对象的方法
    Java-生成指定长度验证码的一种简单思路
    jQuery-表单流程导航
    JS-获取URL请求参数
    AngularJS-Uncaught Error: [$injector:modulerr]
    AngularJS-系统代码的配置和翻译
    JS-改变页面的颜色之变化核心-获取六位的随机数
    JS-为金额添加千分位逗号分割符
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/5553104.html
Copyright © 2020-2023  润新知