Layout is under StatusBar and Soft Keys

删除回忆录丶 提交于 2019-12-05 00:59:13

问题


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?

Edit:

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

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

回答1:


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.




回答2:


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();


来源:https://stackoverflow.com/questions/32128482/layout-is-under-statusbar-and-soft-keys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!