Android 往Framework中添加新资源的方法详解

来源:互联网 发布:离散数学 知乎 编辑:程序博客网 时间:2024/06/05 19:46
有时候我们想在标准的Framework中添加自己的新的资源怎么办呢?
办法就是我们来尝试下。
通过Eclipse的联系,我们可以联想到是否就是简单的把字符串放在res的各个文件夹里面。先来试试看,编译,系统立即报错。为什么呢?
它提示你利用make update-api这个命令来更新public.xml文件或者把这个声明称hide类型。这个肯定不是我们想要的。
所以方法有二:
方法1:
正常添加完资源后,执行make update-api函数。系统更新res/values/public.xml文件。

方法2:正常添加完资源后,手动更改/res/values/public.xml文件。打开public.xml文件。发现结构如下:

<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 0
原创粉丝点击