android去掉黑色状态栏

当你在用别人的app时,发现别人的app状态栏和app的toolbar是一个颜色,在看一下自己的app发现我操 怎么是黑色的状态栏 这时的你肯定不爽,也想来一发,没关系、下面我们一起来一发。
首先你的设置app的主题、一般设置成noactionbar这样方便添加自定义的toolbar。

  <style name="AppBaseTheme" parent="Theme.AppCompat.NoActionBar"> 
        <item name="colorPrimary">@color/material_blue_500</item>
       <item name="colorPrimaryDark">@color/material_blue_700</item>
       <item name="colorAccent">@color/material_green_A200</item>
    </style>

这里的colorPrimaryDark在Android 5.0的时候是可以直接设置成状态栏颜色的、但是4.4就没有这么先进了、下面给出4.4的操作。
面对Android 4.4时在res目录下面建立一个values-v19的目录表示。这里面的东东只支持4.4以上的api,然后再自己的activity里面创建自己的toolbar

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"

        android:fitsSystemWindows="true" >
    </android.support.v7.widget.Toolbar>

    <Button
        android:id="@+id/id_testBt1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="按钮一" />



</LinearLayout>

注意这里的toolbar中的android:fitsSystemWindows=”true”属性设置至关重要如果不这样设置上面的toolbar的背景无法覆盖上面的状态栏,但是如果toolbar的宽度你不设置成wrap_content 你就会发现此时的toolbar变矮了。
但是在5.0上的版本有可能出现,状态栏和下面的toolbar的颜色不太一样,这个时候你只能自己出手强制吧颜色设置成一样,推荐一个git开源库SystemBarTintManager这是一个强大的开源库,你可以随心所欲的操作状态栏的颜色,下面来点源码

SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setStatusBarTintResource(R.color.statusbar_bg);//通知栏所需颜色

好,就这些了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值