谁能告诉我,为什么叠加层在Android Pie中不起作用?是否有执行此操作所需的任何特殊权限。 因为它们实际上并未折旧任何功能,例如:
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
仍在工作,并且工作室未在此代码中给出任何错误。
答案 0 :(得分:0)
这是我用来在其他应用程序上显示对话框覆盖的方式,并且在android pie中运行良好。
void showDialog() {
if (context == null)
context = getApplicationContext();
LayoutInflater layoutInflater = LayoutInflater.from(context);
View promptsView = layoutInflater.inflate(R.layout.popup_unlock, null, false);
Lock9View lock9View = (Lock9View) promptsView.findViewById(R.id.lock_9_view);
Button forgetPassword = (Button) promptsView.findViewById(R.id.forgetPassword);
lock9View.setCallBack(new Lock9View.CallBack() {
@Override
public void onFinish(String password) {
if (password.matches(sharedPreference.getPassword(context))) {
dialog.dismiss();
} else {
Toast.makeText(getApplicationContext(), "Wrong Pattern Try Again", Toast.LENGTH_SHORT).show();
}
}
});
forgetPassword.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(AppCheckServices.this, PasswordRecoveryActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
dialog.dismiss();
}
});
dialog = new Dialog(context, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
} else {
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
}
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
dialog.setContentView(promptsView);
dialog.getWindow().setGravity(Gravity.CENTER);
dialog.setOnKeyListener(new Dialog.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode,
KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK
&& event.getAction() == KeyEvent.ACTION_UP) {
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
}
return true;
}
});
dialog.show();
}