Android沉浸式状态栏、导航栏
16lz
2021-01-23
Android沉浸式状态栏,用的是开源库SystemBarTint。
demo下载地址:http://download.csdn.net/download/shenyuanqing/9226623
效果图:
依次(Android5.0及以上)->(Android4.4及以上)->(Android4.4以下)
步骤:
1.添加类SystemBarTintManager到项目中
2.添加代码
//Android4.4及以上版本才能设置此效果 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //Android5.0版本 if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); //设置状态栏颜色 getWindow().setStatusBarColor(getResources().getColor(R.color.green)); //设置导航栏颜色 getWindow().setNavigationBarColor(getResources().getColor(R.color.green)); }else { //透明状态栏 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //透明导航栏 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); //创建状态栏的管理实例 SystemBarTintManager tintManager = new SystemBarTintManager(this); //激活状态栏设置 tintManager.setStatusBarTintEnabled(true); //设置状态栏颜色 tintManager.setTintResource(R.color.green); //激活导航栏设置 tintManager.setNavigationBarTintEnabled(true); //设置导航栏颜色 tintManager.setNavigationBarTintResource(R.color.green); } }
android:fitsSystemWindows="true"
更多相关文章
- RatingBar 显示正常版本----断点记录
- android 圆角按钮和按钮颜色
- android中实现带图片和checkbox的listview
- 边缘图片android布局属性详解
- Android提示版本更新的实现
- Android缩放图片Bitmap、Drawable
- Android ADT和SDK历史版本离线包下载地址
- Android获取设备型号和系统版本号、mac地址、IP、屏幕的分辨率
- android版本对应表