android-FunuiTheme 資源的替換

來源:互聯網
上載者:User

標籤:

實現資源的替換,需要分為以下幾個步驟

1.找到需要更改的模組 mediatek/packages/apps/FileManager

2.到主題模組下根據包名找到相應資源(以Grass為例) cd vendor/themes/Grass/values com_mediatek_filemanager_colors com_mediatek_filemanager_styles

代碼如下

com_mediatek_filemanager_styles

<?xml version="1.0" encoding="UTF-8"?><resources>    <style name="FileManager.Theme" parent="@android:style/Theme.Funui">        <item name="*android:searchViewTextColor">@color/search_color</item>        <item name="*android:searchViewTextColorHint">@color/search_hint_color</item>        <item name="*android:searchViewSearchIcon">@drawable/com_mediatek_filemanager_search_image</item>    </style>    <style name="FileManager.Theme.NoActionBar" parent="@android:style/Theme.Funui.NoActionBar">    </style></resources>

com_mediatek_filemanager_colors

<?xml version="1.0" encoding="UTF-8"?><resources>    <color name="item_selected_color">#7fed6f00</color>    <color name="action_text_select_color">#ffffff</color>    <color name="search_color">#000000</color>    <color name="search_hint_color">#919192</color></resources>

講解一下這個Theme的工作原理

theme主要就是通過應用的包名來識別應用處理的。首先當一個應用工作的時候,這個主題就會查看自己目錄下是否有這個應用的包名檔案,然後從這個包名檔案中選擇相應的資源去替換到應用中的同名或者加了包名的資源。當然,這個資源可以是圖片,也可以是style,color等

注意:主題下的資源可以替換相應應用的,但是,主題卻不可引用相應應用下的資源。例如<item name="*android:searchViewTextColorHint">@color/search_hint_color_aa</item>  search_hint_color_aa 是filemanager下的顏色,這樣是會報錯的。你想替換或者使用的資源,必須在這個theme下添加 (圖片-drawable* 共用的  顏色-自己相應包名應用下*color style-自己相應包名下的*style)

3.當你添加了資源以後,你需要執行一下p2x c 這個命令的作用,其實就是在xml目錄下的com_mediatek_filemanager.xml裡面註冊你添加的新的資源資訊

<?xml version="1.0" encoding="utf-8"?><resource-redirections>    <item name="color/action_text_select_color">@color/action_text_select_color</item>    <item name="color/item_selected_color">@color/item_selected_color</item>    <item name="color/search_color">@color/search_color</item>    <item name="color/search_hint_color">@color/search_hint_color</item>    <item name="drawable/action_bar_background_pressed">@drawable/com_mediatek_filemanager_action_bar_background_pressed</item>    <item name="drawable/app_filemanager">@drawable/com_mediatek_filemanager_app_filemanager</item>    <item name="drawable/dropdown_ic_arrow_normal_holo_dark">@drawable/com_mediatek_filemanager_dropdown_ic_arrow_normal_holo_dark</item>    <item name="drawable/fm_copy">@drawable/com_mediatek_filemanager_fm_copy</item>    <item name="drawable/fm_cut">@drawable/com_mediatek_filemanager_fm_cut</item>    <item name="drawable/fm_delete">@drawable/com_mediatek_filemanager_fm_delete</item>    <item name="drawable/fm_home_focus">@drawable/com_mediatek_filemanager_fm_home_focus</item>    <item name="drawable/fm_home_ninepatch_focus">@drawable/com_mediatek_filemanager_fm_home_ninepatch_focus</item>    <item name="drawable/fm_tab_focus">@drawable/com_mediatek_filemanager_fm_tab_focus</item>    <item name="drawable/search_image">@drawable/com_mediatek_filemanager_search_image</item>    <item name="style/FileManager.Theme.NoActionBar">@style/FileManager.Theme.NoActionBar</item>    <item name="style/FileManager.Theme">@style/FileManager.Theme</item></resource-redirections>

這個檔案就是上面原理的依據,它就是通過尋找這個檔案來決定是否替換一個資源的。這個當然可以手動添加,當然,為了使用p2x c 自動添加檔案到xml中,我們命名的時候,盡量使用原名,或者在原名前面添加相應的包名。你會發現,執行p2x c以後,它產生的檔案,會自動去點包名。例如

color中添加:<color name="com_mediatek_filemanager_aaa_color">#323232</color>

p2x c

在xml中產生:<item name="color/aaa_color">@color/com_mediatek_filemanager_aaa_color</item>

意義:應用下的aaa_color會替換為theme下的com_mediatek_filemanager_aaa_color

 

android-FunuiTheme 資源的替換

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.