/**
* 进行系统弹窗
*/
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setView(R.layout.dialog_app);
final AlertDialog alertDialog = builder.create();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
} else {
alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
}
View view = alertDialog.getLayoutInflater().inflate(布局资源文件, null);
alertDialog.setView(view, 0, 0, 0, 0);
alertDialog.show();
view.findViewById(R.id.but_up).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getContext(), MainActivity.class));
PreferenceHelper.putString("status", "showPay");
alertDialog.dismiss();
}
});
view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
因为在Android 8.0 以后,要完成系统级弹窗之前的TYPE_SYSTEM_ALERT已经不能使用,改为了TYPE_APPLICATION_OVERLAY。