Android L ActionBarActivity using Feinstein Slding

2020-07-17 16:04发布

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)

6条回答
不美不萌又怎样
2楼-- · 2020-07-17 16:33

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"/>
查看更多
家丑人穷心不美
3楼-- · 2020-07-17 16:34

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);
查看更多
\"骚年 ilove
4楼-- · 2020-07-17 16:37

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.

查看更多
倾城 Initia
5楼-- · 2020-07-17 16:41

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" />
查看更多
时光不老,我们不散
6楼-- · 2020-07-17 16:45

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
查看更多
我欲成王,谁敢阻挡
7楼-- · 2020-07-17 16:50

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};
    }
...
}
查看更多
登录 后发表回答