我正在使用滑动活动,
视图不适合屏幕,它隐藏在导航栏的后面。

我试过了 ,

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


但没有任何效果。

Snackbar隐藏在导航栏后面:
android - 隐藏在导航栏android后面的 View-LMLPHP

最佳答案

嘿,最好的做法是使用tha NavigationDrawer,但对于您的问题,请创建一个扩展CustomSlidingMenu和此类的Override方法的类SlidingMenu。然后使用CustomSlidingMenu代替SlidingMenu,它应该可以正常工作

public class CustomSlidingMenu extends SlidingMenu {
    private boolean mActionbarOverlay = false;

    public CustomSlidingMenu(Context context) {
        super(context);
    }

    public CustomSlidingMenu(Activity activity, int slideStyle) {
        super(activity, slideStyle);
    }

    public CustomSlidingMenu(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomSlidingMenu(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @SuppressLint("NewApi")
    @Override
    protected boolean fitSystemWindows(Rect insets) {
        if (mActionbarOverlay) return true;

        setMyPadding(insets);
        return true;
    }

    @TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
    @Override
    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
        if (mActionbarOverlay) return insets.consumeSystemWindowInsets();

        Rect rect = new Rect(
                insets.getSystemWindowInsetLeft(),
                insets.getSystemWindowInsetTop(),
                insets.getSystemWindowInsetRight(),
                insets.getSystemWindowInsetBottom()
        );

        setMyPadding(rect);

        return insets.consumeSystemWindowInsets();
    }

    private void setMyPadding(Rect rect) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
            switch (manager.getDefaultDisplay().getRotation()) {
                case Surface.ROTATION_90:
                case Surface.ROTATION_270:
                    rect.right += getNavBarWidth();
                    break;
                case Surface.ROTATION_180:
                    rect.top += getNavBarHeight();
                    break;
                default:
                    rect.bottom += getNavBarHeight();
            }
        }

        setPadding(
                rect.left, rect.top, rect.right, rect.bottom
        );
    }

    private int getNavBarWidth() {
        return getNavBarDimen("navigation_bar_width");
    }

    private int getNavBarHeight() {
        return getNavBarDimen("navigation_bar_height");
    }

    private int getNavBarDimen(String resourceString) {
        Resources r = getResources();
        int id = r.getIdentifier(resourceString, "dimen", "android");
        if (id > 0) {
            return r.getDimensionPixelSize(id);
        } else {
            return 0;
        }
    }
}


我假设您在我的方法中使用AppCompat,因此原因是SlidingMenu设置的填充与AppCompat配置冲突并覆盖它们。

关于android - 隐藏在导航栏android后面的 View ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37694627/

10-09 01:58