您的位置:首页 > 移动开发 > Android开发

Android改变状态栏颜色导航不变

2015-07-20 10:44 519 查看
(1)

在你的activity oncreate 中添加

[code] getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setStatusBarTintResource(R.color.actionbar_bg);
       
    }

(2) 设置头部边距

     contentView = getWindow().getDecorView().findViewById(android.R.id.content);
     contentView.setPadding(0,getStatusBarHeight(),0,0);

     
(3)
public int getStatusBarHeight() {
  int result = 0;
  int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
  if (resourceId > 0) {
      result = getResources().getDimensionPixelSize(resourceId);
  }
  return result;
}
[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: