Android 往 Framework中添加新的資源

來源:互聯網
上載者:User

有時候我們想在標準的Framework中添加自己的新的資源怎麼辦呢?

辦法就是我們來嘗試下。

通過Eclipse的聯絡,我們可以聯想到是否就是簡單的把字串放在res的各個檔案夾裡面。先來試試看,編譯,系統立即報錯。為什麼呢?

它提示你利用make update-api這個命令來更新public.xml檔案或者把這個聲明稱hide類型。這個肯定不是我們想要的。

所以方法有二:

方法1:正常添加完資源後,執行make update-api函數。系統更新res/values/public.xml檔案。

方法2:正常添加完資源後,手動更改/res/values/public.xml檔案。開啟public.xml檔案。發現結構如下:

 

  1. <resources>  
  2.   <!-- We don't want to publish private symbols in Android.R as part of the   
  3.        SDK.  Instead, put them here. -->  
  4.   <private-symbols package="com.android.internal" />  
  5.   <!-- AndroidManifest.xml attributes. -->  
  6.   <eat-comment />  
  7. <!-- ===============================================================   
  8.      Resources for version 1 of the platform.  
  9.      =============================================================== -->  
  10.   <eat-comment />  
  11.   <public type="string" name="cancel" id="0x01040000" />  
  12.   <public type="string" name="copy" id="0x01040001" />  
  13.   <public type="string" name="copyUrl" id="0x01040002" />  
  14.    <public type="style" name="TextAppearance.Widget.TextView.SpinnerItem" id="0x01030052" />  
  15.   <public type="style" name="TextAppearance.WindowTitle" id="0x01030053" />  
  16.   <public type="attr" name="theme" id="0x01010000" />  
  17.   <public type="attr" name="label" id="0x01010001" />  
  18.   <public type="attr" name="icon" id="0x01010002" />  
  19.   <public type="attr" name="name" id="0x01010003" />  
  20.   <public type="attr" name="manageSpaceActivity" id="0x01010004" />  
  21.   <public type="attr" name="allowClearUserData" id="0x01010005" />  
  22.   <public type="attr" name="permission" id="0x01010006" />  
  23.   <public type="attr" name="readPermission" id="0x01010007" />  
  24.   <public type="attr" name="writePermission" id="0x01010008" />  
  25.   <public type="attr" name="protectionLevel" id="0x01010009" />  
  26. <!-- ===============================================================   
  27.      Resources added in version 7 of the platform (Eclair MR1).  
  28.      =============================================================== -->  
  29.   <eat-comment />  
  30.   <public type="attr" name="author" id="0x010102b4" />  
  31.   <public type="attr" name="autoStart" id="0x010102b5" />  
  32.      
  33. </resources>  

這樣,我們可以自己動手添加。

推薦方法1,也是最標準的做法。為啥?

1:避免id重複。

2:麻煩

3:習慣標準化做法。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.