Sherlock
Sherlock

Reputation: 610

Layout is under StatusBar and Soft Keys

I'm not sure how I got this, and I can't find anything similar, but my software navigation and status bar are being drawn over my layout instead of my layout being fit between them.

How do I get my layout to be drawn between them instead of under?

Example

Edit:

It seems this is the culprit, located in the styles:

    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>

Upvotes: 4

Views: 3275

Answers (2)

Geral Torres
Geral Torres

Reputation: 109

Use this to obtain the margin bottom to RootView and the navigation doesn't overlap

public static int getSoftButtonsBarSizePort(Activity activity) {
// getRealMetrics is only available with API 17 and +
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int usableHeight = metrics.heightPixels;
    activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
    int realHeight = metrics.heightPixels;
    if (realHeight > usableHeight)
        return realHeight - usableHeight;
    else
        return 0;
}
return 0;
}

And the OnCreate Method

var rootView = ((ViewGroup)this.FindViewById(Android.Resource.Id.Content)).GetChildAt(0);
        //var rootView = this.Window.DecorView.RootView;

        ViewGroup.MarginLayoutParams layoutParams;

        if (rootView.LayoutParameters != null)
        {
            layoutParams = (ViewGroup.MarginLayoutParams)rootView.LayoutParameters;

        }
        else
        {
            layoutParams = new ViewGroup.MarginLayoutParams(rootView.Width, rootView.Height);
        }


        var margin = GetSoftButtonsBarSizePort(this);

        layoutParams.SetMargins(rootView.Left, rootView.Top, rootView.Right, margin);
        rootView.LayoutParameters = layoutParams;
        rootView.RequestLayout();

Upvotes: 1

Hussein El Feky
Hussein El Feky

Reputation: 6707

Just fix this:

<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">false</item>

or simply remove them. These attributes make your StatusBar and NavigationBar semi-transparent, so that's why your layout was acting like a full screen.

Upvotes: 6

Related Questions