首页 > 其他 > 详细

AlertDilog

时间:2021-04-19 11:14:48      阅读:25      评论:0      收藏:0      [点我收藏+]

AlertDilog

弄一个button

<Button
        android:id="@+id/button_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="616dp"
        android:text="AD"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.518"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

找到它

   Button button = findViewById(R.id.button_1);

设置一个点击事件

button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
                builder.setTitle("这里输入标题").setMessage("设置文本").setNegativeButton("按钮一", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //按钮一的点击事件
                        Toast.makeText(LoginActivity.this,"NegativeButton",Toast.LENGTH_SHORT).show();
                    }
                }).setPositiveButton("按钮二", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //按钮二的点击事件
                        Toast.makeText(LoginActivity.this,"PositiveButton",Toast.LENGTH_SHORT).show();
                    }
                }).create().show();
            }
        });

如果有红色的,就应该是LoginActivity,把它改成你的Activity的名字,比如MainActivity

AlertDilog

原文:https://www.cnblogs.com/zz222/p/14675509.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!