我在API 23上的自定義對話框中遇到了一個問題,它正在崩潰。爲什麼自定義對話框不適用於API 23?
final Dialog dialog = new Dialog(getActivity());
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.progress_dialog);
dialog.setCancelable(false);
dialog.show();
崩潰報告:
android.view.WindowManager$BadTokenException: Unable to add window [email protected] -- permission denied for this window type
at android.view.ViewRootImpl.setView(ViewRootImpl.java:598)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:310)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:86)
at android.app.Dialog.show(Dialog.java:319)
at com.example.hello.fragment.ExploreFragment.exploreBeers(ExploreFragment.java:255)
at com.example.hello.fragment.ExploreFragment$4.onEditorAction(ExploreFragment.java:203)
at android.widget.TextView.onEditorAction(TextView.java:4773)
at com.android.internal.widget.EditableInputConnection.performEditorAction(EditableInputConnection.java:139)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:304)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:152)
at android.app.ActivityThread.main(ActivityThread.java:5497)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
清單權限:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
它不是在所有的工作我感到有點迷惑,請您通過我的職務,並建議我一些解決方案。
權限被拒絕此窗口類型。在啓動該功能之前,您需要詢問運行時間權限。 –
嘿謝謝你能告訴我如何做到這一點? –
使用LayoutParams.TYPE_TOAST或TYPE_APPLICATION_PANEL – siddhesh