protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //针对5.0以上系统使用StatusBarUtil可能无效的情况 getWindow().requestFeature(Window.FEATURE_NO_TITLE); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(Color.TRANSPARENT); window.setNavigationBarColor(Color.TRANSPARENT); } setContentView(R.layout.activity_main); ViewUtils.inject(this);
StatusBarUtil.setTransparentForImageView(MainActivity.this, null); }//设置状态栏透明
使用StatusBarUtil时需在build.gardle中添加引用
compile 'com.jaeger.statusbaruitl:library:1.3.2'
关于自定义透明状态栏的问题
最新推荐文章于 2022-10-24 20:19:12 发布