·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> Android开发 >> Android 往Framework中添加新资源的方法详解

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

作者:佚名      Android开发编辑:admin      更新时间:2022-07-23
有时候我们想在标准的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,也是最标准的做法。为啥?
1:避免id重复。
2:麻烦
3:习惯标准化做法。