laobie / StatusBarUtil

A util for setting status bar style on Android App.
http://t.cn/Rq746Kb
Apache License 2.0
8.81k stars 1.72k forks source link

未添加CoordinatorLayout支持? #54

Closed jasonlee3652 closed 8 years ago

jasonlee3652 commented 8 years ago

如果toolsbar在CoordinatorLayout中,猴哥你写的代码是不支持的?我自己修改了下,猴哥过目一下。另外问一下4.4的系统中,图片可以透过状态栏吗?

/**
     * 为 DrawerLayout 布局设置状态栏透明
     *
     * @param activity     需要设置的activity
     * @param drawerLayout DrawerLayout
     */
    public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            return;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
        } else {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }

        ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
        // 内容布局不是 LinearLayout 时,设置padding top
        if (contentLayout instanceof CoordinatorLayout) {
            View toolbarView = contentLayout.findViewById(R.id.toolbar);
            if (toolbarView != null) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) toolbarView.getLayoutParams();
                    layoutParams.setMargins(0, getStatusBarHeight(activity), 0, 0);
                }
            }
        } else {
            if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
                contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
            }
        }

        // 设置属性
        ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
        drawerLayout.setFitsSystemWindows(false);
        contentLayout.setFitsSystemWindows(false);
        contentLayout.setClipToPadding(true);
        drawer.setFitsSystemWindows(false);
    }

猴哥看下这样修改有没问题,另外回答一下我上面问的问题,谢谢了

laobie commented 8 years ago

支持的,你说的不支持是怎么回事呢?有图不

laobie commented 8 years ago

@jasonlee3652 另外问一下4.4的系统中,图片可以透过状态栏吗? 可以的,你下载下我的 demo 看看,是可以的

laobie commented 8 years ago

没有后续的回答,关闭 issue