Android沉浸式(设置状态栏颜色)
16lz
2021-01-23
目前为止只支持4.4以上的版本。
首先需要用到systembartint
compile好之后就可以了,直接上代码了
public class BaseActivity extends FragmentActivity { protected SystemBarTintManager tintManager; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); initWindow(); } @TargetApi(19) protected void initWindow() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); tintManager = new SystemBarTintManager(this); setStatusBarColor(getResources().getColor(R.color.colorAccent)); tintManager.setStatusBarTintEnabled(true); } } protected void setStatusBarColor(int color) { if (tintManager != null) tintManager.setStatusBarTintColor(color); } protected void disableSystemBarTint() { if (tintManager != null) tintManager.setStatusBarTintEnabled(false); }}
public class MainActivity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);// setStatusBarColor(Color.parseColor("#000000"));// disableSystemBarTint(); }}你可以直接继承,在BaseActivity里面设置状态栏的颜色,如果你要设置其他的颜色,可以通过
setStatusBarColor()来设置,
disableSystemBarTint();是根据你title的颜色去设置的,希望能帮到你!
更多相关文章
- 重写Android Log的输出,只在debug的时候输出,release 的版本不输出
- android之Notification版本兼容性问题
- Android版本28用http请求CLEARTEXT communication to www.xxxxx.
- android获取版本信息、屏幕信息和设备编号
- android高版本Toast问题
- 设置android的布局文件的背景颜色为黑色
- Android统一依赖多个不同版本的Support v7包
- Android 动态设置颜色