我需要向点击我的 Android 应用程序上的按钮的用户显示一条小短信,在 IOS 上我只需要创建一个 AlertView,它使用起来很简单,但在 Android 上我很困难,因为解决方案似乎困难十倍。我看到我需要使用 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 来简单地显示警报。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)