• Android-Styles and Themes [From API Guide]


    This blog was opened 5 months ago and it has 57 posts now,but the poor thing is by now no one has commented on any articles by now..How miserable and pathetic...Even if I've been writing some bullshit you should at least give me some response...Never mind, I was originally meant to writer to remind myself.

    And sometimes I feel a little reluctant to read English than Chinese, even when I carefully read them I feel they are illustrated so clearly even more explicit than many Chinese vague articles.When I learn something from google's developer.android.com , I want to note them here.But I think why, firstly, why should I note them when I can visit them any time on google's website; secondly ,why use Chinese?

    There's a proverb in China called "A good memory is not as good as a broken pen point" ,meaning that one would remember something better when he or she write it down.Ok now I decide to write things down when I learn something from android developers.

    -------------------------

    Styles and Themes:

    Styles in Android share a similar philosophy to cascading stylesheets in web design—they allow you to separate the design from the content.

    For example, by using a style, you can take this layout XML:

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#00FF00"
        android:typeface="monospace"
        android:text="@string/hello" />

    And turn it into this:

    <TextView
        style="@style/CodeFont"
        android:text="@string/hello" />

    All of the attributes related to style have been removed from the layout XML and put into a style definition calledCodeFont, which is then applied with the style attribute.  

    theme is a style applied to an entire Activity or application, rather than an individual View. When a style is applied as a theme, every View in the Activity or application will apply each style property that it supports. For example, you can apply the same CodeFont style as a theme for an Activity and then all text inside that Activity will have green monospace font.

    Define Styles

    1.To create a set of styles, save an XML file in the res/values/ directory of your project. The name of the XML file is arbitrary, but it must use the .xml extension and be saved in the res/values/ folder.(I thought it could be saved in any folder,is it just a recommendation?)

    2.The root node of the XML file must be <resources>.

    3.For each style you want to create, add a <style> element to the file with a name that uniquely identifies the style (this attribute is required). Then add an <item> element for each property of that style, with a name that declares the style property and a value to go with it (this attribute is required). The value for the <item> can be a keyword string, a hex color, a reference to another resource type, or other value depending on the style property. Here's an example file with a single style:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="CodeFont" parent="@android:style/TextAppearance.Medium">
            <item name="android:layout_width">fill_parent</item>
            <item name="android:layout_height">wrap_content</item>
            <item name="android:textColor">#00FF00</item>
            <item name="android:typeface">monospace</item>
        </style>
    </resources>

    -----it's Tomb-sweeping Day , to be continued-----

    Inheritance

     You can use this to inherit properties from an existing style and then define only the properties that you want to change or add. You can inherit from styles that you've created yourself or from styles that are built into the platform

     For example, you can inherit the Android platform's default text appearance and then modify it:

    <style name="GreenText" parent="@android:style/TextAppearance">
            <item name="android:textColor">#00FF00</item>
    </style>
    

    kind of like the "override" concept  in Java huh..

  • 相关阅读:
    浅谈.NET下的多线程和并行计算系列文章索引
    浅谈.NET下的多线程和并行计算(六)线程池基础下
    浅谈.NET下的多线程和并行计算(八)Winform中多线程编程基础上
    项目优化经验——垃圾回收导致的性能问题
    浅谈.NET下的多线程和并行计算(五)线程池基础上
    站点静态资源优化合并解决方案
    浅谈.NET下的多线程和并行计算(二)线程基本知识
    浅谈.NET下的多线程和并行计算(十二)CLR via C#第三版阅读笔记(1)
    原谅我的说谎
    索爱手机GPRS的OTA设置[转]
  • 原文地址:https://www.cnblogs.com/larrylawrence/p/3647266.html
Copyright © 2020-2023  润新知