Reputation: 6877
I have created a small library to place Views beside/above/below an existing View (e.g. Help arrow or something like that), I use
MainView.getLocationOnScreen(..);
to determine the position of the Main View where the Sibling View will be placed nearby.
Usually I'm determining the top (Y) of the Main View by the method above minus the height of the status bar using the following method:
protected boolean isTranslucentStaturBar()
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = ((Activity) mainActionView.getContext()).getWindow();
--> return // SOME EXPRESSION TO DETERMINE IF THE STATUS BAR IS TRANSLUCENT <--- ?????
// I Need to know what expression I need to write here
// i.e. How to ready the flag: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
}
return false;
}
protected int getStatusBarHeight() {
if (isTranslucentStaturBar()) {
return 0;
}
int result = 0;
int resourceId = mainActionView.getContext().getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = mainActionView.getContext().getResources().getDimensionPixelSize(resourceId);
}
return result;
}
My problem is with Androids >= Kitkat, where you can actually set the status bar to translucent and window content spread to fill the place below the status bard icons..
Upvotes: 2
Views: 1354
Reputation: 6462
Thanks mate! Translated to Xamarin Android:
bool trans; var flags = Window.Attributes.Flags; if ((flags & WindowManagerFlags.TranslucentStatus) == WindowManagerFlags.TranslucentStatus) trans = true; else trans = false;
Upvotes: 0
Reputation: 6877
OK so after digging deeply, I reached out to this solution:
protected boolean isTranslucentStatusBar()
{
Window w = ((Activity) mainActionView.getContext()).getWindow();
WindowManager.LayoutParams lp = w.getAttributes();
int flags = lp.flags;
// Here I'm comparing the binary value of Translucent Status Bar with flags in the window
if ((flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) {
return true;
}
return false;
}
Upvotes: 7