Android 状态栏改变的方法:
SystemBarTintManager tintManager;
/**
* 设置系统状态栏的颜色 Exception
*/
@SuppressLint("InlinedApi")
@SuppressWarnings("unused")
private void setActionBarTitle(RelativeLayout main_relative, int position)
throws Exception {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
ApplicationVar appvar = (ApplicationVar) getApplication();
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
if (true) {
winParams.flags |= bits;
} else {
winParams.flags &= ~bits;
}
win.setAttributes(winParams);
if (tintManager == null) {
tintManager = new SystemBarTintManager(this);
}
if (position == 1) {
int status = appvar.GetValue(Constants.STATUS_HEIGHT, 0);
if (status == 0) {
Class<?> c = Class.forName("com.android.internal.R$dimen");
Object obj = c.newInstance();
java.lang.reflect.Field field = c.getField("status_bar_height");
int x = Integer.parseInt(field.get(obj).toString());
status = getResources().getDimensionPixelSize(x);// 获取状态栏的高度
appvar.saveValue(Constants.STATUS_HEIGHT, status);
}
tintManager.setStatusBarTintEnabled(true);
main_relative.setPadding(0, status, 0, 0);
tintManager.setStatusBarAlpha(10);
tintManager.setStatusBarTintResource(R.color.red);
} else {
// 激活状态栏设置
tintManager.setStatusBarTintEnabled(true);
main_relative.setPadding(0, 0, 0, 0);
tintManager.setNavigationBarTintEnabled(true);
tintManager.setStatusBarAlpha(0);
}
}
}