application content goes behind the navigation bar in android L
Asked Answered
T

9

37

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.

Trompe answered 3/2, 2015 at 16:1 Comment(2)
Try : View.bringToFront();Othello
@user863873:layout should not use this space.It should be above these buttons.Trompe
T
46

Here is the solution.

Most of the layouts get solved by adding these properties in values-v21 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

Trompe answered 5/2, 2015 at 10:32 Comment(2)
I added the following to my style <item name="android:windowTranslucentNavigation">true</item> <item name="android:fitsSystemWindows">true</item> It works! No content is being drawn behind the navigation bar. Except now my navigation bar is a dark gray instead of black. Putting TranslucentNavigation to false makes the bar black, but content draws behind it. Think you could explain why these attributes work, and how to keep the navigation bar black?Nerves
You have defined the method but you did not tell us how to use it or calling it. Can you kindly tell us where to call that method from and how to use what its returning.Centroid
H
7

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

android:fitsSystemWindows="true"
Haire answered 17/6, 2018 at 10:56 Comment(1)
Not working on pie may be it's not working since android MNellenelli
P
6

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

Pevzner answered 10/1, 2017 at 5:42 Comment(0)
M
4

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));
Marleen answered 8/1, 2017 at 13:15 Comment(0)
S
3

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.

Spoken answered 11/12, 2017 at 14:48 Comment(1)
For pre-lambda: .setOnApplyWindowInsetsListener (findViewById(android.R.id.content), new OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { // .. } } );Commines
B
1

I tried many answers above, but none of them worked for me. I have wrapped my relative layout in which my button (which has to be attached to bottom) in another linear layout. It worked for me magically.

If someone can add the reason for this, it would be more helpful.

Bagwig answered 8/4, 2020 at 22:16 Comment(0)
A
1

In most cases and by default, the navigation bar should always be below the app unless you've triggered a setting.

If that's the behavior you want to make sure you're not running this line:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
Andrews answered 20/1, 2021 at 20:34 Comment(0)
L
0

Setting softInputMode of popupWindow to SOFT_INPUT_ADJUST_RESIZE resolves the issue.

Leveloff answered 13/11, 2016 at 11:24 Comment(0)
O
0

Try this before setcontent view of your java, My problem got solved by this`

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);`
Ope answered 20/5, 2020 at 12:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.