I'm attempting to change the size of my activity in OnAttachedToWindow, so that it appears floating. In order to calculate it's new size, I need to get the visible display frame for the decor view. But it returns 0.
I actually need to get the height of the status bar. I followed this guide: How to get Android screen height minus status bar in pixel?
But it doesn't work.
How can I get the height of the status bar (or the visible display frame) in OnAttachedToWindow?
I would have thought this possible since, apparently, it has been attached, and drawing can commence, according to the Android docs.
Here is my Activity code:
public override void OnAttachedToWindow()
{
base.OnAttachedToWindow();
var decorView = Window.DecorView;
var rect = new Rect();
decorView.GetWindowVisibleDisplayFrame(rect);
// rect is now 0
var lp = (WindowManagerLayoutParams)decorView.LayoutParameters;
// change some stuff...
WindowManager.UpdateViewLayout(decorView, lp);
}