4

I'm using AppCompat v21 with the Style "NoActionBar" and add a Action/Toolbar in onCreate.

Also a SlidingMenu of Feinstein is added and that causes the problem that the that the Activity (and therefore the inside Fragments) overlap with the navigation buttons of Android (it is not fully shown, cut off at the bottom)

if i add:

android:layout_marginBottom="48dp"

in the layout it everything is visible (of course).

On Android 4.4. everything is shown properly.

What am I missing on Android L using the support lib?

SlidingMenu added in onCreate:

super.onCreate(..)
setContentView(..)

menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
menu.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);
menu.setMenu(R.layout.menu);
menu.setBehindWidthRes(200dp);

Solution:

The issue is stated here https://github.com/jfeinstein10/SlidingMenu/issues/680 (including the solution)

Slding Menu to SLIDING_CONTENT
OR: update the SlidingMenu source like mentioned in the link aboce

Better Solution:
(also working with Samsung devices on 5.0) - provided by withaay

Adding the following lines to the SlidingMenu constructors has worked for me. I didn't have to make any other code changes.

if(Build.VERSION.SDK_INT >= 21)
    setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
ddd
  • 481
  • 6
  • 17

6 Answers6

8

Adding the following lines to the SlidingMenu constructors has worked for me. I didn't have to make any other code changes.

if(Build.VERSION.SDK_INT >= 21)
    setSystemUiVisibility(SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
whitaay
  • 493
  • 1
  • 6
  • 18
2

The issue is stated here https://github.com/jfeinstein10/SlidingMenu/issues/680 (including the solution)

  • Slding Menu to SLIDING_CONTENT
  • OR: update the SlidingMenu source like mentioned in the link aboce
ddd
  • 481
  • 6
  • 17
0

Try to add android:minHeight="?attr/actionBarSize" to your Toolbar.

 <android.support.v7.widget.Toolbar
      android:id="@+id/toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
0

You've added the Toolbar in your main LinearLayout, but you are still using match_parent for the height of your FrameLayout container. Try filling up the remaining space of your LinearLayout instead:

<FrameLayout
      android:id="@+id/container"
      android:layout_weight="1"
      android:layout_width="match_parent"
      android:layout_height="0dp" />
Blacklight
  • 3,809
  • 2
  • 33
  • 39
  • thx, but that also had no influence on the layout. i have to mention that it is also to big for the screen **without** a toolbar. so i think it is more a generell problem – ddd Jan 06 '15 at 11:09
  • ok i made a mistake. it is caused by the slidingmenu of feinstein. updated the question. any ideas? – ddd Jan 06 '15 at 11:43
  • I don't see anything updated in your question relating to that? For the sliding menu, just use exactly the example layouts that you find in the documentation. I did and it works great for me on 4.4 as well as on Lollipop, nothing is cut off. – Blacklight Jan 06 '15 at 11:54
  • Sorry then, I'm not at all familiar with that library, but it's probably related to that yes. I only used the standard navigation drawer: http://developer.android.com/training/implementing-navigation/nav-drawer.html – Blacklight Jan 06 '15 at 12:11
  • thx anyways :) i was so focused on the appcompat and acitivity cause the menu doesn't show anything wrong.. but i is this issue [link](https://github.com/jfeinstein10/SlidingMenu/issues/680) and can be resolved like mentioned there. – ddd Jan 06 '15 at 12:41
0

If you are trying to use Fenstein Menu with App Compat probably you'll get an issue with your slding menu. Your sliding menu will slide from behind of your phone's bottom bar.

To fix this locate

YOUR-PROJECT/sliding-menu/src/com/jeremyfeinstein/slidingmenu/lib/SlidingMenu.java

Find

int bottomPadding = insets.bottom;

And replace it

int bottomPadding = insets.bottom;
        if (Build.VERSION.SDK_INT >= 21) {
            Resources resources = getContent().getResources();
            int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
            if (resourceId > 0) {
                bottomPadding += resources.getDimensionPixelSize(resourceId);
            }
        }

I searched hard about this problem and the solution above worked for me.

savepopulation
  • 11,736
  • 4
  • 55
  • 80
0

The following code worked for me: basically you always call setSlidingActionBarEnabled(false) and then compute and set the correct height of your root view according to the below formula, depending on the fact that you have a navigation bar or not.

public class MyActivity extends SlidingActivity {
...
    @Override
    public void onCreate(Bundle savedInstanceState) {    
...
        setSlidingActionBarEnabled(false);
        mBtmNavBarSize = getNavigationBarSize(this);
        mUsableScreenSize = getAppUsableScreenSize(this);

        mRootView = (View) findViewById(android.R.id.content);
        mRootView.post(new Runnable() {

            @Override
            public void run() {
                int[] hs = getStatusAndTitleBarHeight();
                int nfh = mRootView.getHeight();
                if (mBtmNavBarSize.y > 0)
                    nfh = mUsableScreenSize.y - mBtmNavBarSize.y - hs[1];
                ViewGroup.LayoutParams lp2 = mRootView.getLayoutParams();
                lp2.height = nfh;
                mRootView.setLayoutParams(lp2);
            }

        });

...
    public static Point getNavigationBarSize(Context context) {
        Point appUsableSize = getAppUsableScreenSize(context);
        Point realScreenSize = getRealScreenSize(context);

        // navigation bar on the right
        if (appUsableSize.x < realScreenSize.x) {
            return new Point(realScreenSize.x - appUsableSize.x, appUsableSize.y);
        }

        // navigation bar at the bottom
        if (appUsableSize.y < realScreenSize.y) {
            return new Point(appUsableSize.x, realScreenSize.y - appUsableSize.y);
        }

        // navigation bar is not present
        return new Point();
    }

    // get usable screen size (real minus bottom navigation bar)
    public static Point getAppUsableScreenSize(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        return size;
    }

    public static Point getRealScreenSize(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        Point size = new Point();

        if (Build.VERSION.SDK_INT >= 17) {
            display.getRealSize(size);
        } else if (Build.VERSION.SDK_INT >= 14) {
            try {
                size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
                size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
            } catch (IllegalAccessException e) {
            } catch (InvocationTargetException e) {
            } catch (NoSuchMethodException e) {
            }
        }

        return size;
    }

    private int[] getStatusAndTitleBarHeight() {
        Rect rectangle = new Rect();
        Window window = getWindow();
        window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
        int statusBarHeight = rectangle.top;
        int contentViewTop =
                window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
        int titleBarHeight = contentViewTop - statusBarHeight;
        return new int[]{statusBarHeight, titleBarHeight};
    }
...
}
PJ_Finnegan
  • 1,981
  • 1
  • 20
  • 17