2 xiaorourou945 xiaorourou945 于 2016.01.29 13:44 提问

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

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

5个回答

bdmh
bdmh   Ds   Rxr 2016.01.29 13:49

你设置fullscreen全屏了吗

xiaorourou945
xiaorourou945 fullscreen不是连状态栏都没了吗
接近 2 年之前 回复
xiaorourou945
xiaorourou945   2016.01.29 14:13

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

qigemingzitt
qigemingzitt   2016.01.29 14: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 14: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
a_running_wolf   2016.02.02 17:23
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!