Ce morceau de code fonctionne semble fonctionner dans api Android 16 - 22, mais ne fonctionne pas dans l'API 23. Je suis simplement en train d'essayer d'afficher une popup popup avec des options dans et assombrir l'arrière-plan ci-dessous la popupWindow:
WindowPopUp windowPopUp =
new WindowPopUp(mContext, mPlaces.get(position), position, fromSearch);
windowPopUp.showAtLocation(v, Gravity.CENTER, 0, 0);
View parent = (View) windowPopUp.getContentView().getParent();
//dim the window in the background
WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams p = (WindowManager.LayoutParams) parent.getLayoutParams();
p.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
p.dimAmount = 0.4f;
wm.updateViewLayout(parent, p);
l'exécution de cette code entraîne une erreur:
03-18 21:55:19.674 8814-8814/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp, PID: 8814
java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.view.WindowManager$LayoutParams
at com.bemyapp.adapter.OuterPlaceAdapter$5.onLongClick(OuterPlaceAdapter.java:400)
at android.view.View.performLongClick(View.java:5237)
at android.view.View$CheckForLongPress.run(View.java:21121)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
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)
Qu'est-ce qui ne va pas?
Pour autant que je sache, WindowManager.LayoutParams
étend ViewGroup.LayoutParams
et quand je l'appelle parent.getLayoutParams()
, il retourne un ViewGroup.LayoutParams
donc il ne devrait pas être un classCastException
.
Mais pourquoi cela fonctionne-t-il dans les API 16 - 22 mais pas dans l'API 23? – Simon
Ajouté une modification. Fondamentalement, vous dépendiez d'un détail d'implémentation qu'ils ont modifié. –
C'est une terrible nouvelle. Je suppose que je devrais changer toutes mes popupwindows à DialogActivity. Popupwindows ne sont pas une bonne idée de conception si cela est vrai. – Simon