This piece of code works seems to work in android api 16 - 22 but does not work in api 23. I\'m simply trying to display a popupwindow with options in it and dim the backgro
There is a class cast exception. You're casting a ViewGroup.LayoutParams
to a WindowManager.LayoutParams
. If the actual object returned is an instance of a different child of ViewGroup.LayoutParams
(for example, FrameLayout.LayoutParams
) then the cast is illegal. In this case the view called parent isn't directly in a window, its inside a FrameLayout
. So calling getLayoutParams
returns a FrameLayout.LayoutParams
, not a WindowsManager.LayoutParams
.
If it is working in 22 and not 23, its quite possible that they changed how popups are done in 23. Relying on the parent popup being directly inside of a window was never a safe assumption, your code always had the risk of being broken by an OS update.
Just add one more .getParent() to access the container.
if (android.os.Build.VERSION.SDK_INT > 22) {
container = (View) pwindow.getContentView().getParent().getParent();
}else{
container = (View) pwindow.getContentView().getParent();
}