Android修改状态栏背景色
来源:互联网 发布:ichart.js下载 编辑:程序博客网 时间:2024/05/18 03:18
这是小弟我第一次写博客,如有不足的地方,敬请原谅,有点紧张现在。
当我们在进行安卓开发的时候,我们经常会发现,当我们给一个页面设置标题栏的时候,往往其背景色又和手机自带的状态栏背景色不一样,但又发现很多NB的应用其颜色又都是设置成一样的,那么他们是怎么做的呢,请看下面的步骤:
1.首先在所布局的activity中添加以下两个属性:
android:clipToPadding="true"android:fitsSystemWindows="true"这是为了防止我们的标题栏和状态栏重叠到一起
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:background="@color/theambacground" android:clipToPadding="true" android:fitsSystemWindows="true" android:orientation="vertical">
2.我们为了方便此方法的调用和功能的实现,可以将相应的方法放在application里面
public void initSystemBar(Activity activity,int color_id) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(activity, true); } SystemBarTintManager tintManager = new SystemBarTintManager(activity); tintManager.setStatusBarTintEnabled(true); // 使用颜色资源 tintManager.setStatusBarTintResource(color_id);}@TargetApi(19)private void setTranslucentStatus(Activity activity, boolean on) { Window win = activity.getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams);}3.方法的调用和参数的传递:
MyApplication.getApp().initSystemBar(this, R.color.theamcolor);只需要将这行代码放入onCreate()方法里就可以了,这个activity的标题栏的颜色也就可以设置成自己想要的颜色了。
最后,欢迎大家关注和观看,如有不足的地方还请指教。
1 0
- Android修改状态栏背景色
- android 沉浸式状态栏 背景色修改
- android系统修改状态栏背景色以及文字颜色
- Android修改状态栏和导航栏背景色
- android 修改背景色
- Android actionBar 修改背景色
- android 修改主题背景色
- Android actionBar 修改背景色
- android修改ActionBar背景色
- Android改变状态栏statusbar背景色
- android 改变状态栏的背景色
- 设置状态栏背景色
- android-沉浸状态栏以及状态栏背景色如何设置
- android沉浸状态栏和顶部状态栏背景色的设置
- Android-沉浸状态栏以及状态栏背景色如何设置
- Android更改状态栏背景色之后,view被状态栏挡住
- iOS[试试] - 修改状态栏的文字颜色和背景色
- Android ListView点击行高亮(修改背景色)
- Permission denied (publickey,keyboard-interactive). fatal: The remote end hung up unexpectedly 解决方法
- Android在SQLite中使用事务
- python新技术
- kaprekar常数(6174猜想)
- HTML的绝对定位与相对定位
- Android修改状态栏背景色
- linux开机自启服务的一些技巧
- 静态方法类
- 【cdoj 1349】柱爷大战滑稽王 lcs转lis+二分查找(二分啊)
- 八核King6818开发板U盘挂载查看及Ubuntu烧录
- CSS3 overflow-x 属性
- Mybatis中的resultType和resultMap
- 免装版tomcat注册成windows系统服务方法
- 【SSO单点系列】(1):CAS4.0 环境的搭建