赞
踩
在flutter载体页面,修改flutter页面的状态栏背景颜色,这两个方法就可以实现: /** * 6.0级以上的沉浸式布局 * */ public static void fitSystemBar(Activity activity) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; Window window = activity.getWindow(); View decorView = window.getDecorView(); //View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN--能够使得我们的页面布局延伸到状态栏之下,但不会隐藏状态栏。也就相当于状态栏是遮盖在布局之上的 //View.SYSTEM_UI_FLAG_FULLSCREEN -- 能够使得我们的页面布局延伸到状态栏,但是会隐藏状态栏。 //WindowManager.LayoutParams.FLAG_FULLSCREEN int systemUiVisibility = decorView.getSystemUiVisibility(); decorView.setSystemUiVisibility(systemUiVisibility | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { WindowManager.LayoutParams lp = window.getAttributes(); lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; window.setAttributes(lp); } // window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(Color.BLACK); //修改这个颜色,看一下效果 }
/** * 6.0及以上的状态栏色调 * @param light true:白底黑字,false:黑底白字 */ public static void lightStatusBar(Activity activity, boolean light) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return; Window window = activity.getWindow(); View decorView = window.getDecorView(); int visibility = decorView.getSystemUiVisibility(); if (light) { visibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; } else { visibility &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; } decorView.setSystemUiVisibility(visibility); }
网上的还有其它方案,可以参考,
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。