设置通知栏的背景颜色或全幅背景
2017-07-25 16:04
232 查看
1. 效果图
2. 在xml布局中添加一个背景图片 , 这里就不贴代码了
3. 在MainActivity中添加如下代码
2. 在xml布局中添加一个背景图片 , 这里就不贴代码了
3. 在MainActivity中添加如下代码
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); translucentStatusBar(this, false); } static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) { Window window = activity.getWindow(); //添加Flag把状态栏设为可绘制模式 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); if (hideStatusBarBackground) { //如果为全透明模式,取消设置Window半透明的Flag window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //设置状态栏为透明 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { window.setStatusBarColor(Color.TRANSPARENT); } //设置window的状态栏不可见 window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } else { //如果为半透明模式,添加设置Window半透明的Flag window.addFlags(WindowManager.LayoutParams.[b]FLAG_TRANSLUCENT_STATUS); //设置系统状态栏处于可见状态 window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); } //view不根据系统窗口来调整自己的布局 ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT); View mChildView = mContentView.getChildAt(0); if (mChildView != null) { ViewCompat.setFitsSystemWindows(mChildView, false); ViewCompat.requestApplyInsets(mChildView); } }
相关文章推荐
- iOS平台设置系统状态栏(通知栏、顶部状态栏)样式背景颜色或透明
- eclipse背景颜色及文字大小设置
- statusBar 背景颜色设置问题
- #linux# 自定义设置vim的背景颜色
- UITableViewCell通过cell.backgroundColor设置背景颜色为什么没有效果
- Android 代码中设置控件背景颜色,以TextView为例
- SecureCRT 字体颜色与背景设置
- WM_CTLCOLOR设置控件设置背景和字体颜色
- 直接设置Activity的背景颜色
- [Tip] 养眼小贴士(Windows背景颜色设置为淡绿色)
- Android布局背景颜色设置
- 关于NavigationBar背景图片和颜色的设置
- EXT.NET 为 FormPanel设置背景颜色
- 设置UITableView Section的背景颜色和字体颜色 ----------自
- VC/MFC如何设置对话框背景颜色
- 设置导航栏的背景颜色和字体
- Qt中设置widget背景颜色/图片的注意事项(使用样式表 setStyleSheet)good
- bootStrap 设置鼠标滑过背景颜色
- qt中关于QWidget的背景颜色和背景图片的设置
- c++关于设置设置控制台背景及字体颜色