开源项目修改状态栏

android 4.4 提供了一套能透明的系统ui样式给状态栏和导航栏,这样的话就不用向之前那样天天面对着黑乎乎的上下两条黑栏了,还能够调成跟activity 同样的样式,造成一个完整的主题。java


首先要打开activity的透明主题功能,能够把activity的主题设置继承*.TranslucentDecor 主题,而后设置android:windowTranslucentNavigation 或者android:windowTranslucentStatus的主题属性为true,又或者在activity的代码里面开启FLAG_TRANSLUCENT_NAVIGATION 或是 FLAG_TRANSLUCENT_STATUS的window窗口标识。因为透明主题不能在4.4之前的版本里面使用,因此系统样式跟之前没有区别,也就是看不到任何变化,这是一个兼容模式,这个模式能够兼容到api 10;android

<activitygit

            android:name=".MainActivity"github

            android:label="@string/app_name" api

            android:theme="@android :style/Theme.Holo.NoActionBar.TranslucentDecor"app

            android:windowTranslucentNavigation="true"ui

           >this

而后下载 SystemBarTint,地址是https://github.com/hexiaochun/SystemBarTint,将里面的SystemBarTintManager.java直接拷到本身的项目中,在activity的onCreate()添加以下代码:spa

SystemBarTintManager tintManager = new SystemBarTintManager(this);
		tintManager.setStatusBarTintEnabled(true);
		tintManager.setNavigationBarTintEnabled(true);
		tintManager.setTintColor(Color.RED);
相关文章
相关标签/搜索