在对话框中显示消息的替代方法是什么?
What is the alternative way of show message in dialog?
我想生成一个警告对话框,用户可以通过该对话框授予权限。
但是showMessage
方法在android工作室有问题。
错误代码:
"Cannot resolve method ' showMessage(Java.lang.String, anonymous android.content.DialogInterface.OnClickListener)'
他们有任何替代代码吗?
这是当前代码:
if (!shouldShowRequestPermissionRationale(Manifest.permission.WRITE_CONTACTS)){
showMessage("bi sahab ro allow kon ",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
requestPermissions(new String[
{Manifest.permission.WRITE_EXTERNAL_STORAGE},
REQUEST_CODE_ASK_PERMISSIONS);
}
});
}
尝试使用此代码进行警报对话框。应该可以。
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(_context);
AlertDialog.Builder builder = alertDialogBuilder
.setTitle("title goes here")
.setMessage("message goes here")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
{
// code body
}
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// code body
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.setCancelable(true);
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
希望对您有所帮助!!!
我想生成一个警告对话框,用户可以通过该对话框授予权限。
但是showMessage
方法在android工作室有问题。
错误代码:
"Cannot resolve method ' showMessage(Java.lang.String, anonymous android.content.DialogInterface.OnClickListener)'
他们有任何替代代码吗?
这是当前代码:
if (!shouldShowRequestPermissionRationale(Manifest.permission.WRITE_CONTACTS)){
showMessage("bi sahab ro allow kon ",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
requestPermissions(new String[
{Manifest.permission.WRITE_EXTERNAL_STORAGE},
REQUEST_CODE_ASK_PERMISSIONS);
}
});
}
尝试使用此代码进行警报对话框。应该可以。
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(_context);
AlertDialog.Builder builder = alertDialogBuilder
.setTitle("title goes here")
.setMessage("message goes here")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
{
// code body
}
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// code body
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.setCancelable(true);
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
希望对您有所帮助!!!