application content goes behind the navigation bar

2020-01-27 02:50发布

enter image description here

As you can see my "Got It" button is behind the navigation bar.Not able to fix it!!! I have tried

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

As well as setting it in layout file.

my theme in value-21 is :

 <style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">false</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:fitsSystemWindows">true</item>
    </style>

Its the same case with all the screens throughout the application.

Please Help.

6条回答
男人必须洒脱
2楼-- · 2020-01-27 02:53

Setting softInputMode of popupWindow to SOFT_INPUT_ADJUST_RESIZE resolves the issue.

查看更多
神经病院院长
3楼-- · 2020-01-27 02:58

Simply set this in your Activity's onCreate(), while setting up content view :

int mScreenWidth = getWindowManager().getDefaultDisplay().getWidth();
int mScreenHeight = getWindowManager().getDefaultDisplay().getHeight();
View view = getLayoutInflater().inflate(R.layout.activity_main, null);
setContentView(view, new ViewGroup.LayoutParams(mScreenWidth, mScreenHeight));
查看更多
爷、活的狠高调
4楼-- · 2020-01-27 03:06

Use this code in your onCreate method of your Activity(If you have BaseActivity you can do this there so all activities apply this):

ViewCompat.setOnApplyWindowInsetsListener(
            findViewById(android.R.id.content), (v, insets) -> {
                ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
                params.bottomMargin = insets.getSystemWindowInsetBottom();
                return insets.consumeSystemWindowInsets();
            });

When a layout has this flag, it means that this layout is asking the system to be applied window insets. In our case that would mean, that FrameLayout desires to be applied a padding that is equal to status bar’s height.

查看更多
做自己的国王
5楼-- · 2020-01-27 03:09

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

Note: By using the above solutions everything work but I was also using PopupWindow in my app.The layout of the PopupWindow get messed up in android L. Look for the issue and the solution here

查看更多
forever°为你锁心
6楼-- · 2020-01-27 03:15

It is so simple, just add this line to your parent layout xml:

android:fitsSystemWindows="true"
查看更多
再贱就再见
7楼-- · 2020-01-27 03:16

For nice user experience you should not need to block navigation keys area using android:windowTranslucentNavigation

rather here is the better solution, if you are using ResideMenu library then simply add this method in ResideMenu.java

  @Override
protected boolean fitSystemWindows(Rect insets) {
    int bottomPadding = insets.bottom;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Resources resources = getResources();
        int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
        if (resourceId > 0) {
            bottomPadding += resources.getDimensionPixelSize(resourceId);
        }
    }
    this.setPadding(viewActivity.getPaddingLeft() + insets.left, viewActivity.getPaddingTop() + insets.top,
            viewActivity.getPaddingRight() + insets.right, viewActivity.getPaddingBottom() + bottomPadding);
    insets.left = insets.top = insets.right = insets.bottom = 0;
    return true;
}

and if you are using SlidingMenu library then change mod to SLIDING_CONTENT by:

menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);

Hope it will save your time

查看更多
登录 后发表回答