Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 5: button underneath softnavigation bar (Showcaseview legacy)

I am using the legacy ShowcaseView for Android. I notice that the Android 5 emulator puts the OK button underneath the softnavigation bar, whereas Android <= KITKAT did not have this behaviour.

See the OK button in the lower right corner here: http://imgur.com/SZtIcHr

I already tried android:fitsSystemWindows="true" but no success. Here is the relevant code in the ShowcaseView.java that I found:

    mEndButton = (Button) LayoutInflater.from(context).inflate(R.layout.showcase_button, null);

(Warning: Avoid passing null as the view root (needed to resolve layout parameters on the inflated layout's root element)) [..]

    if (!mOptions.noButton && mEndButton.getParent() == null) {
        RelativeLayout.LayoutParams lps = (LayoutParams) generateDefaultLayoutParams();
        lps.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        if (getConfigOptions().showcaseId==3) 
            lps.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        else
            lps.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        int margin = ((Number) (metricScale * 12)).intValue();
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) // TODO: LOLLIPOP workaround
            lps.setMargins(margin, margin, margin, margin*5);
        else
            lps.setMargins(margin, margin, margin, margin);
        lps.height = LayoutParams.WRAP_CONTENT;
        lps.width = LayoutParams.WRAP_CONTENT;
        mEndButton.setLayoutParams(lps);
        mEndButton.setText(buttonText != null ? buttonText : getResources().getString(R.string.positive));
        if (!hasCustomClickListener) mEndButton.setOnClickListener(this);
        addView(mEndButton);

I don't know how to change this or how Android 5 / material design has caused this behaviour. I would be happy for a hint! :)

like image 255
ChrisX Avatar asked Nov 07 '14 21:11

ChrisX


People also ask

What are the 3 buttons at the bottom of android called?

The classic Navigation bar has the Recents, Home, and Back buttons at the bottom of your screen.

What is the bar at the bottom of the screen called Android?

The Android navigation bar houses the device navigation controls: Back, Home, and Overview. It also displays a menu for apps written for Android 2.3 or earlier.

What are the navigation buttons?

There are four navigational buttons that you can use to move throughout a menu: up, down, right, and left. Each button corresponds to the direction that you can move in a menu. For example, to move right in a menu, press the navigation button that is located on the right side.


2 Answers

For me works set manually the margin bottom without use the margin returned from the method to obtain int margin.

RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

int margin = ((Number) (context.getResources().getDisplayMetrics().density * 12)).intValue();

layoutParams.setMargins(margin, margin, margin, 120);

Hope it works...


The problem has been fixed here...

like image 117
ad3luc Avatar answered Sep 28 '22 22:09

ad3luc


I found very easy fix for this in one of pull requests

Add:

<item name="android:windowDrawsSystemBarBackgrounds">false</item>

to your style/theme in values-v21/styles.xml.

Works well for me, checked on a real device - Nexus 5.

like image 32
michalbrz Avatar answered Sep 29 '22 00:09

michalbrz