Android 往Framework中添加新資源的方法詳解
更新時(shí)間:2013年06月15日 15:12:25 作者:
本篇文章是對Android往Framework中添加新資源的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
有時(shí)候我們想在標(biāo)準(zhǔn)的Framework中添加自己的新的資源怎么辦呢?
辦法就是我們來嘗試下。
通過Eclipse的聯(lián)系,我們可以聯(lián)想到是否就是簡單的把字符串放在res的各個(gè)文件夾里面。先來試試看,編譯,系統(tǒng)立即報(bào)錯(cuò)。為什么呢?
它提示你利用make update-api這個(gè)命令來更新public.xml文件或者把這個(gè)聲明稱hide類型。這個(gè)肯定不是我們想要的。
所以方法有二:
方法1:正常添加完資源后,執(zhí)行make update-api函數(shù)。系統(tǒng)更新res/values/public.xml文件。
方法2:正常添加完資源后,手動更改/res/values/public.xml文件。打開public.xml文件。發(fā)現(xiàn)結(jié)構(gòu)如下:
<resources>
<!-- We don't want to publish private symbols in Android.R as part of the
SDK. Instead, put them here. -->
<private-symbols package="com.android.internal" />
<!-- AndroidManifest.xml attributes. -->
<eat-comment />
<!-- ===============================================================
Resources for version 1 of the platform.
=============================================================== -->
<eat-comment />
<public type="string" name="cancel" id="0x01040000" />
<public type="string" name="copy" id="0x01040001" />
<public type="string" name="copyUrl" id="0x01040002" />
<public type="style" name="TextAppearance.Widget.TextView.SpinnerItem" id="0x01030052" />
<public type="style" name="TextAppearance.WindowTitle" id="0x01030053" />
<public type="attr" name="theme" id="0x01010000" />
<public type="attr" name="label" id="0x01010001" />
<public type="attr" name="icon" id="0x01010002" />
<public type="attr" name="name" id="0x01010003" />
<public type="attr" name="manageSpaceActivity" id="0x01010004" />
<public type="attr" name="allowClearUserData" id="0x01010005" />
<public type="attr" name="permission" id="0x01010006" />
<public type="attr" name="readPermission" id="0x01010007" />
<public type="attr" name="writePermission" id="0x01010008" />
<public type="attr" name="protectionLevel" id="0x01010009" />
<!-- ===============================================================
Resources added in version 7 of the platform (Eclair MR1).
=============================================================== -->
<eat-comment />
<public type="attr" name="author" id="0x010102b4" />
<public type="attr" name="autoStart" id="0x010102b5" />
</resources>
這樣,我們可以自己動手添加。
推薦方法1,也是最標(biāo)準(zhǔn)的做法。為啥?
1:避免id重復(fù)。
2:麻煩
3:習(xí)慣標(biāo)準(zhǔn)化做法。
辦法就是我們來嘗試下。
通過Eclipse的聯(lián)系,我們可以聯(lián)想到是否就是簡單的把字符串放在res的各個(gè)文件夾里面。先來試試看,編譯,系統(tǒng)立即報(bào)錯(cuò)。為什么呢?
它提示你利用make update-api這個(gè)命令來更新public.xml文件或者把這個(gè)聲明稱hide類型。這個(gè)肯定不是我們想要的。
所以方法有二:
方法1:正常添加完資源后,執(zhí)行make update-api函數(shù)。系統(tǒng)更新res/values/public.xml文件。
方法2:正常添加完資源后,手動更改/res/values/public.xml文件。打開public.xml文件。發(fā)現(xiàn)結(jié)構(gòu)如下:
復(fù)制代碼 代碼如下:
<resources>
<!-- We don't want to publish private symbols in Android.R as part of the
SDK. Instead, put them here. -->
<private-symbols package="com.android.internal" />
<!-- AndroidManifest.xml attributes. -->
<eat-comment />
<!-- ===============================================================
Resources for version 1 of the platform.
=============================================================== -->
<eat-comment />
<public type="string" name="cancel" id="0x01040000" />
<public type="string" name="copy" id="0x01040001" />
<public type="string" name="copyUrl" id="0x01040002" />
<public type="style" name="TextAppearance.Widget.TextView.SpinnerItem" id="0x01030052" />
<public type="style" name="TextAppearance.WindowTitle" id="0x01030053" />
<public type="attr" name="theme" id="0x01010000" />
<public type="attr" name="label" id="0x01010001" />
<public type="attr" name="icon" id="0x01010002" />
<public type="attr" name="name" id="0x01010003" />
<public type="attr" name="manageSpaceActivity" id="0x01010004" />
<public type="attr" name="allowClearUserData" id="0x01010005" />
<public type="attr" name="permission" id="0x01010006" />
<public type="attr" name="readPermission" id="0x01010007" />
<public type="attr" name="writePermission" id="0x01010008" />
<public type="attr" name="protectionLevel" id="0x01010009" />
<!-- ===============================================================
Resources added in version 7 of the platform (Eclair MR1).
=============================================================== -->
<eat-comment />
<public type="attr" name="author" id="0x010102b4" />
<public type="attr" name="autoStart" id="0x010102b5" />
</resources>
這樣,我們可以自己動手添加。
推薦方法1,也是最標(biāo)準(zhǔn)的做法。為啥?
1:避免id重復(fù)。
2:麻煩
3:習(xí)慣標(biāo)準(zhǔn)化做法。
相關(guān)文章
Android三種方式生成矢量圖之VectorDrawable類使用詳解
這篇文章主要介紹了Android三種方式生成矢量圖的VectorDrawable類,2014年6月26日的I/O?2014開發(fā)者大會上谷歌正式推出了Android?L,它帶來了全新的設(shè)計(jì)語言Material?Design,新的API也提供了這個(gè)類VectorDrawable2023-02-02
Android無限循環(huán)RecyclerView的完美實(shí)現(xiàn)方案
這篇文章主要介紹了Android無限循環(huán)RecyclerView的完美實(shí)現(xiàn)方案,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06
Android動畫學(xué)習(xí)筆記之補(bǔ)間動畫
這篇文章主要為大家詳細(xì)介紹了Android動畫學(xué)習(xí)筆記之補(bǔ)間動畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-12-12
Android 判斷屏幕開關(guān)狀態(tài)方式總結(jié)
這篇文章主要介紹了Android 判斷屏幕開關(guān)狀態(tài)方式總結(jié)的相關(guān)資料,需要的朋友可以參考下2016-10-10
Android編程實(shí)現(xiàn)圖片背景漸變切換與圖層疊加效果
這篇文章主要介紹了Android編程實(shí)現(xiàn)圖片背景漸變切換與圖層疊加效果,涉及Android圖形特效的相關(guān)操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2017-01-01
基于Android實(shí)現(xiàn)個(gè)性彩色好看的二維碼
二維碼在我們?nèi)粘I钪袩o處不在,今天小編通過本教程給大家介紹基于Android實(shí)現(xiàn)個(gè)性彩色好看的二維碼,需要的朋友參考下吧2016-02-02

