Android Studio —— 弹窗

效果

<iframe allowfullscreen="true" data-mediaembed="bilibili" id="tUJbKSkK-1642416975868" src="https://player.bilibili.com/player.html?aid=765654325"></iframe>


代码
<?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"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <Button
        android:id="@+id/Btn"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:onClick="BtnClick"
        android:text="对话框">
    </Button>

</LinearLayout>






package com.example.jxdtest;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private String TAG = "JXD";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void BtnClick(View view) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setIcon(R.drawable.ic_baseline_access_alarm_24)
                .setTitle("通知")
                .setMessage("触发按钮点击事件")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Log.e(TAG, "onClick: 点下确定按钮");
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Log.e(TAG, "onClick: 点下取下按钮");
                    }
                })
                .setNeutralButton("中间", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Log.e(TAG, "onClick: 点下中间按钮");
                    }
                })
                .create()
                .show();
        Log.e("abcc", "BtnClick: ");
    }
}

关注

笔者 - jxd

微信公众号搜索 “码农总动员” 或 微信扫描下方二维码,了解更多你不知道的XX,O(∩_∩)O

Android Studio —— 弹窗

上一篇:Android Studio Set of source 代码源集


下一篇:Windows:快速安装zookeeper教程