開源項目修改狀態欄

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);
相關文章
相關標籤/搜索