修改setting的ui風格

<1>修改系統的色調

在設置的主題中添加:

<!-- 更改首頁圖標顏色 -->
<item name="android:colorAccent">#ff6900</item>

這樣只是修改掉Setting內部的顏色,一些鏈接到系統其他應用的顏色沒有改變
還需要在源碼的framework/base/core/res/res/values/ 目錄下,修改對應的主題顏色,我這使用的是material主題:themes_material.xml
可以看到主題中

dark主題
<item name="colorAccent">@color/accent_material_dark</item>
light主題
<item name="colorAccent">@color/accent_material_light</item>

再去對應的color_material.xml 文件中查找,修改對應的顏色

修改framework res需要重新編譯framework res模塊:
編譯framework res部分

1.初始化環境 : . ./build/envsetup.sh

2.選擇模塊: lunch

3.編譯res: make framework-res

4.將編譯好的模塊推到機器:adb remount && adb push ./out/…/framework-res.apk /system/framework/framework-res.apk

5.重啓系統 adb reboot

注意:我使用的是本地eng版本纔有權限,push

<2>修改系統的Switch的風格

1.首先在主題中添加:

<!-- For SwitchPreference SwitchBar -->
<item name="@*android:switchStyle">@style/customSwitchStyle</item>

再在style中添加自定義switchStyle:

<style name="customSwitchStyle" parent="@*android:style/Widget.Material.CompoundButton.Switch">
        <item name="android:track">@drawable/switch_track</item>
        <item name="android:thumb">@drawable/switch_thumb</item>
        <item name="android:textOn">""</item>
        <item name="android:textOff">""</item>
        <item name="android:switchMinWidth">0dip</item>
    </style>

對應的資源文件:
switch_track.png

這裏寫圖片描述

switch_thumb.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/switch_disable" android:state_enabled="false"/>
    <item android:drawable="@drawable/switch_on" android:state_checked="true"></item>
    <item android:drawable="@drawable/switch_off"></item>

</selector>

switch_disable.png switch_on.png switch_off.png :

這裏寫圖片描述這裏寫圖片描述這裏寫圖片描述

同樣需要修改系統個framework中源碼res:
在material主題中將switchStyle屬性修改爲上面自定義的風格,將資源放在對應的drawable中
編譯framework-res ……等就修改啦控件switch的默認風格
修改其他控件一樣

<3>像上面修改後發現還有一些系統的ui沒有改變顏色

這就需要修改SystemUI中的顏色,在res中的color文件中修改顏色
如果不知道對應是那個顏色,只有去style中去看對應的應用或者直接在color中查找之前改的顏色,直接替換
編譯SystemUI

1.make SystemUI

2.adb remount && adb push ./out/…/SystemUI.apk /system/…/SystemUI.apk //out輸出對應目錄

5.重啓系統 adb reboot

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章