fun getStatusBarHeight(context: Context): Int { val resourceId = context.resources.getIdentifier("status_bar_height", "dimen", "android") if (resourceId > 0) { return context.resources.getDimensionPixelSize(resourceId) } return 0 } fun setStatusBarTransparent(activity: Activity) { if (isFromM()) { // val decorView = activity.window.decorView // val option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE // decorView.systemUiVisibility = option activity.window.statusBarColor = Color.TRANSPARENT } } fun setStatusBarBgColor(activity: Activity, @ColorInt color: Int) { if (isFromM()) { // val decorView = activity.window.decorView // val option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE // decorView.systemUiVisibility = option activity.window.statusBarColor = color } } fun setStatusBarIconColor(activity: Activity, blackIcon: Boolean) { var option = 0; if (blackIcon) { option = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR //白底黑字 } else { option = View.SYSTEM_UI_FLAG_VISIBLE; //默认,黑底白字 } activity.window.decorView.systemUiVisibility = option } fun setStatusBarFullScreen(activity: Activity, isFloat: Boolean) { val decorView = activity.window.decorView val option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE decorView.systemUiVisibility = option }
- @color/white
- @color/white
- @color/white
- true
setSystemUiVisibility(int visibility)传入的实参类型如下:
1.View.SYSTEM_UI_FLAG_VISIBLE :状态栏和Activity共存,Activity不全屏显示。也就是应用平常的显示画面
2.View.SYSTEM_UI_FLAG_FULLSCREEN :Activity全屏显示,且状态栏被覆盖掉
3. View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN :Activity全屏显示,但是状态栏不会被覆盖掉,而是正常显示,只是Activity顶端布 局会被覆盖住
4.View.INVISIBLE : Activity全屏显示,隐藏状态栏
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)