Content going behind Navigation Bar

前端 未结 3 1361
执笔经年
执笔经年 2020-12-18 23:38

I am facing a problem with android 5.0 and above. Whenever I align any view to parent bottom, Content is getting hidden behind the soft navigation button.

A

相关标签:
3条回答
  • 2020-12-19 00:33

    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.

    0 讨论(0)
  • 2020-12-19 00:39

    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;
    }
    
    0 讨论(0)
  • 2020-12-19 00:41
    android:fitsSystemWindows="true"
    

    This worked for me. The view no longer overlaps with soft navigation.

    0 讨论(0)
提交回复
热议问题