xiaorourou945
xiaorourou945
采纳率37.8%
2016-01-29 05:44 阅读 1.9k

android系统状态栏一体化,结果状态栏没有被覆盖上

图片说明各位版主大侠知道是什么原因吗?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

5条回答 默认 最新

  • bdmh bdmh 2016-01-29 05:49

    你设置fullscreen全屏了吗

    点赞 评论 复制链接分享
  • xiaorourou945 xiaorourou945 2016-01-29 06:13

    怪我没有说清楚,状态栏一体化的代码没有覆盖状态栏,吃掉了activity的界面,略略略

    点赞 评论 复制链接分享
  • qigemingzitt IMQS 2016-01-29 06:13
    /**
     * 设置状态栏背景状态  setContentView 后调用 activity的首个控件要加上id:needpanddinglayout
     */
    private void setTranslucentStatus() {
        //判断版本是4.4以上
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window win = getWindow();
            WindowManager.LayoutParams winParams = win.getAttributes();
            final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
            winParams.flags |= bits;
            win.setAttributes(winParams);
    
            SystemStatusManager tintManager = new SystemStatusManager(this);
            //打开系统状态栏控制
            tintManager.setStatusBarTintEnabled(true);
    
            tintManager.setStatusBarTintColor(getResources().getColor(R.color.status_bar_color));
    
            View layoutAll = findViewById(R.id.needpanddinglayout);
            //设置系统栏需要的内偏移
            if (layoutAll != null) {
                layoutAll.setPadding(0, SystemStatusManager.getStatusHeight(this), 0, 0);
            }
        }
    }
    
        SystemStatusManager 类可以下载   再加上一个方法代码:
    
    /**
     * 获得状态栏的高度
     *
     * @param context
     * @return
     */
    public static int getStatusHeight(Context context) {
    
        int statusHeight = -1;
        try {
            Class<?> clazz = Class.forName("com.android.internal.R$dimen");
            Object object = clazz.newInstance();
            int height = Integer.parseInt(clazz.getField("status_bar_height")
                    .get(object).toString());
            statusHeight = context.getResources().getDimensionPixelSize(height);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return statusHeight;
    }
    
    点赞 评论 复制链接分享
  • xiaorourou945 xiaorourou945 2016-01-29 06:38

    public static void initSystemBar(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    setTranslucentStatus(activity, true);
    }
    SystemBarTintManager tintManager = new SystemBarTintManager(activity);
    tintManager.setStatusBarTintEnabled(true);
    // 使用颜色资源
    tintManager.setStatusBarTintResource(R.color.status_color);
    }

    @TargetApi(19)
    private static void setTranslucentStatus(Activity activity, boolean on) {
        Window win = activity.getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }
    
    点赞 评论 复制链接分享
  • a_running_wolf 衷水木先生 2016-02-02 09:23
    点赞 评论 复制链接分享

相关推荐