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

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

问题描述

我需要表现出一点短信到点击我的Andr​​oid应用程序按钮,在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天全站免登陆