请参阅:
if (Build.VERSION.SDK_INT >= 27) {
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
} else {
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST);
}
上面的代码没有使我的应用程序崩溃,但是对于我的Oreo 27 8.0.1版本没有任何作用。
请参阅“非活动性”类中的方法:
private void showAlertDialog(final Context context) {
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context, "test", Toast.LENGTH_SHORT).show();
}
};
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setCancelable(false)
.setPositiveButton("OK", listener);
View view = inflater
.inflate(R.layout.row_passcode_dialog, null);
builder.setView(view);
Dialog dialog = builder.create();
if (Build.VERSION.SDK_INT >= 27) {
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
} else {
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST);
}
dialog.show();
}
还要检查:Permission error is still showing even when added permission in manifest