zoukankan      html  css  js  c++  java
  • 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();
        }
    }
  • 相关阅读:
    KMP 算法 C++
    java RTTI笔记 之Class学习笔记(摘自java编程思想)
    java sql
    event
    mysql 编写存储过程
    《淘宝技术这十年》重读笔记
    关于“产品”的笔记
    程序员,当你遇到一个“坑”
    C盘清理大作战
    android开发笔记
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/5553104.html
Copyright © 2011-2022 走看看