Layout is under StatusBar and Soft Keys
Asked Answered
T

2

4

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>
Tamah answered 20/8, 2015 at 21:12 Comment(4)
Please provide more details or a screenshot. I don't understand your question...Savdeep
I added a crude image. I'm sorry! ha. I didn't realize I finally had permission to upload images.Tamah
Maybe you started your project with a full screen activity or something. Please give us some code, like the Activity section from your AndroidManifest and your xml layout.Mayst
Yeah, try to mention some code please like your layout, styles.xml and your activity.Savdeep
S
6

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.

Savdeep answered 20/8, 2015 at 21:37 Comment(0)
B
1

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();
Bannister answered 27/12, 2018 at 3:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.