android官方開發教程解釋(一)

來源:互聯網
上載者:User

標籤:

最近準備系統學一下android開發,這裡不會照搬原文,只會針對教程中一些難以理解的部分進行解釋,我只是個菜鳥。

在教程第一章——入門基礎裡面,講解android主題的那個小節,大概會有以下的代碼:

<!-- 位置 res/values/themes.xml --><?xml version="1.0" encoding="utf-8"?> <resources>  <!-- 用於程式或活動的主題 -->   <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">       <!-- api_7+ -->       <item name="actionBarStyle">@style/MyActionBar</item>       <!-- api_11+ -->       <item name="android:actionBarStyle">@style/MyActionBar</item>     </style>     <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">         <!-- api_7+ -->         <item name="background">@drawable/actionbar_background</item>         <!-- api_11+ -->         <item name="android:background">@drawable/actionbar_background</item>     </style></resources>

      這段代碼用於定義自己的風格:改變ActionBar的背景,這裡的問題在於api-7與api-11的代碼寫在同一個檔案裡面了,結果無法通過eclipse編譯,解決方案是將這個themes.xml分為多個檔案,工程自動產生的有values-v7、values-v11、values-v14,可以將themes.xml分為幾個不同的版本分別放到不同的values裡去,不同裝置的不同風格大概也是這樣實現的吧?

stackoverflow上的原文:

EDIT : If you want to be able to style your ActionBar to look the same in all API levels, you need to create different folders for the selected api level and create new style.xml / themes.xml files in these folders. For example :

- res  -- values     -- styles.xml     -- themes.xml // API LEVEL 8+ -- values-v11     -- styles.xml     -- themes.xml // API LEVEL 11+ -- values-v14     -- styles.xml     -- themes.xml // API LEVEL 14+

 

在教程中沒有專門說明要添加資源:@drawable/actionbar_background,這裡只要添加一個1x1像素的圖片即可,background的預設效果是展開。

完

 

android官方開發教程解釋(一)

聯繫我們

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