简体   繁体   English

隐藏在导航栏android后面的视图

[英]View hiding behind navigation bar android

I am using Sliding Activity, the View is not fitting to the screen, it is hiding behind the Navigation Bar. 我正在使用Sliding Activity,View不适合屏幕,它隐藏在导航栏后面。

I tried , 我试过了 ,

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

but nothing works. 但没有任何作用。

here Snackbar is hiding behind the Navigation Bar: Snackbar隐藏在导航栏后面: 在此输入图像描述

Hey there best practive would be to use tha NavigationDrawer , but for your problem create a class CustomSlidingMenu which extends SlidingMenu and Override methods like this. 嘿那里最好的practive将是使用tha NavigationDrawer ,但为您的问题创建一个类CustomSlidingMenu ,它扩展SlidingMenuOverride方法,如下所示。 Then use the CustomSlidingMenu instead of SlidingMenu and it should work fine 然后使用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;
        }
    }
}

I'm assuming that you use AppCompat with my approach, so the reason is that the paddings set by the SlidingMenu are in conflict with the AppCompat configurations and Override them. 我假设你使用AppCompat和我的方法,所以原因是SlidingMenu设置的填充与AppCompat配置冲突并覆盖它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM