gpt4 book ai didi

Android 简单的警报对话框

转载 作者:IT老高 更新时间:2023-10-28 12:59:34 25 4
gpt4 key购买 nike

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

最佳答案

您只需在 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 来简单地显示警报。

关于Android 简单的警报对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26097513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com