Reputation: 7560
I have created a rotating tool using Popup Window in Android.
But while rotating the content getting clipped.I am really stuck with this issues.
When i look into source of Popup window , there is a method
/**
* Clip this popup window to the screen, but not to the containing window.
*
* @param enabled True to clip to the screen.
* @hide
*/
public void setClipToScreenEnabled(boolean enabled) {
mClipToScreen = enabled;
setClippingEnabled(!enabled);
}
But i am unable to invoke the same (Shows as can not resolve).
Upvotes: 0
Views: 1333
Reputation: 4852
Using yourWindow.getClass()
on the variable itself didn't work for me. I had to get class statically, like PopupWindow.class
.
There is my working (and safer) helper method:
public static void reflectSetClipToScreenEnabled(PopupWindow popupWindow, boolean enabled) {
try {
Method method = PopupWindow.class.getMethod("setClipToScreenEnabled", boolean.class);
method.invoke(popupWindow, enabled);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
Upvotes: 0
Reputation: 2976
@hide
means that it's not for public use and you can't see it.
If you want to invoke it you can do so via reflection.
Example:
Method method = yourWindow.getClass().getMethod("setClipToScreenEnabled", new Class [] {Boolean.class});
method.invoke(true);
I would advice you to look into exactly how the system calls the method to ensure it works as you expect. Also, when using hidden methods they may or may not exist in all versions (past or future) of Android. You may want to implement the your own type of dialog where you have full controll instead.
Upvotes: 1