Android 6.0状态栏使用灰色文字和图标

参考资料:

http://www.open-open.com/lib/view/open1451119413198.html

https://www.aswifter.com/2015/12/24/android-m-change-statusbar-textcolor/

 

Android StatusBar中的字体和图标默认都是白色的,但是Android在6.0之前是没有办法更改这个颜色,
在Android 6.0中提供了一个SYSTEM_UI_FLAG_LIGHT_STATUS_BAR,可以将其颜色改为灰色。

效果如下图所示:

 

修改状态栏颜色,可以通过以下代码实现:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    getWindow().setBackgroundDrawableResource(R.mipmap.window_bg);
    getWindow().getDecorView().setSystemUiVisibility(
      View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    getWindow().setStatusBarColor(Color.TRANSPARENT);
 }

 

另外我们如果需要去除Toolbar的阴影效果,可以通过设置elevation属性修改:

<android.support.design.widget.AppBarLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       app:elevation="0dp"
       android:background="@android:color/transparent"
       android:theme="@style/AppTheme.AppBarOverlay">

       <android.support.v7.widget.Toolbar
           android:id="@+id/toolbar"
           android:layout_width="match_parent"
           android:layout_height="?attr/actionBarSize"
           android:background="@android:color/transparent"
           app:popupTheme="@style/AppTheme.PopupOverlay" />
           
</android.support.design.widget.AppBarLayout>

 

posted @ 2016-04-12 15:39  因为全栈所以架构  阅读(762)  评论(0编辑  收藏  举报