android官方开发教程解释(一)

最近准备系统学一下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的默认效果是拉伸。


 

posted @ 2015-03-10 16:42  myjhaha  阅读(286)  评论(0编辑  收藏  举报