Android 简单的警报对话框 [英] Android simple alert dialog

查看:44
本文介绍了Android 简单的警报对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要向在我的 Android 应用程序上单击按钮的用户显示一条小短信,在 IOS 上我只需要创建一个易于使用的 AlertView,但是对于 Android,我正在努力,因为该解决方案似乎是 x10 倍更难.我看到我需要使用 DialogFragment 但我不明白如何使它工作,有人可以解释一下吗?另外,我的解决方案是否正确,或者有什么更简单的方法可以向用户显示简单的短信?

I need to show a little text message to the users that clicks a button on my Android app, on IOS I just had to create an AlertView that it's simple to use but with Android i'm struggling because the solution seems x10 times harder. I saw that I need to use a DialogFragment but I can't understand how to make it work, can someone explain? Also, is my solution right or there is something easier to show a simple text message to users?

推荐答案

您只需在 onClick 中执行此操作:

You would simply need to do this in your onClick:

AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("Alert");
alertDialog.setMessage("Alert message to be shown");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
    new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
alertDialog.show();

我不知道您从哪里看出您需要 DialogFragment 来简单地显示警报.

I don't know from where you saw that you need DialogFragment for simply showing an alert.

这篇关于Android 简单的警报对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆