Android method for adding new resources to Framework

  • 2020-05-10 18:50:26
  • OfStack

Sometimes we want to add our own new resources to the standard Framework?
The solution is let's try.
Through the Eclipse connection, we can think about whether it is simply a matter of putting strings in various folders of res. Try it first, compile, and the system will immediately report an error. Why is that?
It prompts you to use the make update-api command to update the public.xml file or to declare this as type hide. This is definitely not what we want.
Therefore, there are two methods:
Method 1: after adding the resource normally, execute the make update-api function. System update res/values/public xml file.
Method 2: normal after adding resources, manual changes/res values/public xml file. Open the public.xml file. The structure of the discovery is as follows:

<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>  

That way, we can add it ourselves.
Recommended method 1 is also the most standard practice. Why?
1: avoid id duplication.
2: trouble
3. Get used to standardized practices.

Related articles: