Content going behind Navigation Bar

前提是你 提交于 2019-12-01 04:21:27

Here is the solution.

Most of the layouts get solved by adding these properties in value-21 style.xml

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

for others, I have calculated the hight of navigation bar and add margin to my view .

 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;
}

I don't have a off-the-shelve solution, but this might be of help. The activity_main.xml root element states it should fit the system window: android:fitsSystemWindows="true".

I guess you'll have to find a way to detect whether the bottom navbar is on screen, and if true, add extra margin-bottom to your activity layout.

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