状态栏沉浸,系统状态栏颜色更改

系统状态栏颜色标识如下:


res/values/style.xml:

<!-- 主题 -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <!-- 窗口背景颜色 -->
<item name="android:windowBackground">@color/windowBackground</item>
<!-- 应用的主要色调,actionBar默认使用该颜色,Toolbar导航栏的底色 -->
<item name="colorPrimary">@color/colorPrimary</item>
<!-- 应用的主要暗色调,statusBarColor默认使用该颜色 -->
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<!-- 应用的强调色,CheckBox,RadioButton,SwitchCompat等一般控件的选中效果默认采用该颜色 -->
<item name="colorAccent">@color/colorAccent</item>
<!--  ActionMode覆盖Actionbar,不顶下来 -->
<item name="windowActionModeOverlay">true</item>
<item name="android:windowContentOverlay">@null</item>
<!--  ActionMode的颜色 -->
<item name="actionModeBackground">@color/colorPrimary</item>
</style>

 

//自定义full_screen 样式:

<style name="NoTitle_FullScreen" parent="AppTheme"> <!--自定义主题名称-->
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>

 

 

 

1.colorPrimary 应用的主要色调,actionBar默认使用该颜色,Toolbar导航栏的底色

2.colorPrimaryDark 应用的主要暗色调,statusBarColor默认使用该颜色

3.statusBarColor 状态栏颜色,默认使用colorPrimaryDark

4.windowBackground 窗口背景颜色

5.navigationBarColor 底部栏颜色

6.colorForeground 应用的前景色,ListView的分割线,switch滑动区默认使用该颜色

7.colorBackground 应用的背景色,popMenu的背景默认使用该颜色

8.colorAccent CheckBox,RadioButton,SwitchCompat等一般控件的选中效果默认采用该颜色

9.colorControlNormal CheckBox,RadioButton,SwitchCompat等默认状态的颜色。

10.colorControlHighlight 控件按压时的色调

11.colorControlActivated 控件选中时的颜色,默认使用colorAccent

12.colorButtonNormal 默认按钮的背景颜色

13.editTextColor:默认EditView输入框字体的颜色。

14.textColor Button,textView的文字颜色

15.textColorPrimaryDisableOnly RadioButton checkbox等控件的文字

16.textColorPrimary 应用的主要文字颜色,actionBar的标题文字默认使用该颜色

17.colorSwitchThumbNormal: switch thumbs 默认状态的颜色. (switch off)

============================================================================================

@和?的区别
 style="?android:attr/progressBarStyleHorizontal"
 style="@android:style/Widget.ProgressBar.Horizontal"
1
2
在设置style的时候既可以使用@也可以使用?,他们有什么区别呢??

使用@表示使用固定的style,而不会跟随Theme改变,这style可以在对应的style.xml中找到。
使用?表示从Theme中查找引用的资源名,这个google叫预定义样式,用在多主题时的场景,属性值会随着主题而改变。(?需要和attr配合使用)
=========================================================================================

 

res/layout/title_view.xml:

<android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="?android:attr/actionBarSize"
    android:background="?attr/colorPrimary"  // 跟随系统theme 的颜色
    >


    <TextView
        android:id="@+id/tv_back"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:text="back"
        />

    <TextView
        android:id="@+id/tv_back2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"

        android:text="back"
        android:layout_marginLeft="30dp"
        android:layout_gravity="center"
        />
    
    <TextView
        android:id="@+id/tv_back3"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"

        android:text="back"
        android:layout_marginLeft="30dp"
        android:layout_gravity="right"
        />

    


</android.support.v7.widget.Toolbar>

效果如下:

 

 

============================================================================

 

沉浸式状态栏库:

https://github.com/gyf-dev/ImmersionBar

api 'com.gyf.barlibrary:barlibrary:2.3.0'

 

1:
使用系统的fitsSystemWindows属性,在布局的根节点"指定fitsSystemWindows为true,然后在代码中使用ImmersionBar指定状态栏的颜色,详情参看此页面的实现
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/darker_gray"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        app:title="方法二"
        app:titleTextColor="@android:color/white" />

    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_margin="20dp"
        android:layout_weight="1"
        android:lineSpacingExtra="3dp"
        android:textColor="@android:color/black"
        android:textSize="15sp" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="我是底部" />
</LinearLayout>
2:
<activity
    android:name=".activity.Over2Activity"
    android:windowSoftInputMode="adjustPan" />

3:在Activity中使用:

ImmersionBar.with(this).barColor(R.color.colorPrimary).init();
ImmersionBar.with(this)
             .transparentStatusBar()  //透明状态栏,不写默认透明色
             .transparentNavigationBar()  //透明导航栏,不写默认黑色(设置此方法,fullScreen()方法自动为true)
             .transparentBar()             //透明状态栏和导航栏,不写默认状态栏为透明色,导航栏为黑色(设置此方法,fullScreen()方法自动为true)
             .statusBarColor(R.color.colorPrimary)     //状态栏颜色,不写默认透明色
             .navigationBarColor(R.color.colorPrimary) //导航栏颜色,不写默认黑色
             .barColor(R.color.colorPrimary)  //同时自定义状态栏和导航栏颜色,不写默认状态栏为透明色,导航栏为黑色
             .statusBarAlpha(0.3f)  //状态栏透明度,不写默认0.0f
             .navigationBarAlpha(0.4f)  //导航栏透明度,不写默认0.0F
             .barAlpha(0.3f)  //状态栏和导航栏透明度,不写默认0.0f
             .statusBarDarkFont(true)   //状态栏字体是深色,不写默认为亮色
             .flymeOSStatusBarFontColor(R.color.btn3)  //修改flyme OS状态栏字体颜色
             .fullScreen(true)      //有导航栏的情况下,activity全屏显示,也就是activity最下面被导航栏覆盖,不写默认非全屏
             .hideBar(BarHide.FLAG_HIDE_BAR)  //隐藏状态栏或导航栏或两者,不写默认不隐藏
             .addViewSupportTransformColor(toolbar)  //设置支持view变色,可以添加多个view,不指定颜色,默认和状态栏同色,还有两个重载方法
             .titleBar(view)    //解决状态栏和布局重叠问题,任选其一
             .titleBarMarginTop(view)     //解决状态栏和布局重叠问题,任选其一
             .statusBarView(view)  //解决状态栏和布局重叠问题,任选其一
             .fitsSystemWindows(true)    //解决状态栏和布局重叠问题,任选其一,默认为false,当为true时一定要指定statusBarColor(),不然状态栏为透明色,还有一些重载方法
             .supportActionBar(true) //支持ActionBar使用
             .statusBarColorTransform(R.color.orange)  //状态栏变色后的颜色
             .navigationBarColorTransform(R.color.orange) //导航栏变色后的颜色
             .barColorTransform(R.color.orange)  //状态栏和导航栏变色后的颜色
             .removeSupportView(toolbar)  //移除指定view支持
             .removeSupportAllView() //移除全部view支持
             .navigationBarEnable(true)   //是否可以修改导航栏颜色,默认为true
             .navigationBarWithKitkatEnable(true)  //是否可以修改安卓4.4和emui3.1手机导航栏颜色,默认为true
             .fixMarginAtBottom(true)   //已过时,当xml里使用android:fitsSystemWindows="true"属性时,解决4.4和emui3.1手机底部有时会出现多余空白的问题,默认为false,非必须
             .addTag("tag")  //给以上设置的参数打标记
             .getTag("tag")  //根据tag获得沉浸式参数
             .reset()  //重置所以沉浸式参数
             .keyboardEnable(true)  //解决软键盘与底部输入框冲突问题,默认为false,还有一个重载方法,可以指定软键盘mode
             .keyboardMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)  //单独指定软键盘模式
             .setOnKeyboardListener(new OnKeyboardListener() {    //软键盘监听回调
                   @Override
                   public void onKeyboardChange(boolean isPopup, int keyboardHeight) {
                       LogUtils.e(isPopup);  //isPopup为true,软键盘弹出,为false,软键盘关闭
                   }
              })
             .init();  //必须调用方可沉浸式

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值