免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1116 | 回复: 0
打印 上一主题 下一主题

[Android] Resources: Style & Themes [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-22 08:51 |只看该作者 |倒序浏览
  1. Docs
    • Applying Styles and Themes
      http://developer.android.com/guide/topics/ui/themes.html
    • System Styles
      http://developer.android.com/reference/android/R.style.html
    • System Themes
      http://developer.android.com/reference/android/R.styleable.html#Theme
    • Style Resources
      http://developer.android.com/guide/topics/resources/style-resource.html
    • Referencing style attributes
      http://developer.android.com/guide/topics/resources/accessing-resources.html#ReferencesToThemeAttributes
    • xxx
  2. Summary
    • What is style
      A style is a set of one or more formatting attributes that you can apply as a unit to individual elements in your layout(View or Window).
      A style can specify properties such as height, padding, font color, font size, background color, and much more. A style is defined in an XML resource that is separate from the XML that specifies the layout.
      For example, you could define a style that specifies a certain text size and color, then apply it to only specific View elements.

    • What is theme
      A theme is a set of one or more formatting attributes that you can apply as a unit to all activities in an application, or just a single activity, rather than an individual View.
      For example, you could define a theme that sets specific colors for the window frame and the panel background, and sets text sizes and colors for menus. This theme can then be applied to specific activities or the entire application.
    • xxx
  3. Style Inherits
    1st way: use parent attribute.
    2nd way: use name attribute with '.' seperated, such as <style name="CodeFont.Red"> which inherits from stule CodeFont.

    If you want to remove an attribute from derived style, you can override the attribute and set "@null" as its value, ie:
    <resources>
        <style name="Theme.NoBackground" parent="android:Theme">
            <item name="android:windowBackground">@null</item>
        </style>
    </resources>

  4. Referencing style attributes
    A style attribute resource allows you to reference the value of an attribute defined in the currently-applied theme.

    To reference a style attribute, the name syntax is
    ?[<package_name>:][<resource_type>/]<resource_name>


    Sample:
    <EditText
        id="text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="?android:textColorSecondary"
        android:text="@string/hello_world" />

    Here, the android:textColor attribute specifies the name of a style attribute in the current theme. Android now uses the value applied to the android:textColorSecondary style attribute as the value for android:textColor in this widget. Because the system resource tool knows that an attribute resource is expected in this context, you do not need to explicitly state the type (which would be ?android:attr/textColorSecondary)—you can exclude the attr type.

    Another sample:
    <ProgressBar android:id="@+id/progress_horizontal"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:max="100"
            android:progress="50"
            android:secondaryProgress="75" />

    <TextView
            style="?android:attr/listSeparatorTextViewStyle"
            android:text="@string/listSeparatorTextViewStyle"
            android:layout_marginTop="5dip"
        />

  5. xxx
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP