Android Chinese Translation-styles and themes (styles and themes)

Source: Internet
Author: User

This article translated from: https://developer.android.com/guide/topics/ui/themes.html

Style and theme words are specialized terms that are used directly below and not translated.

Styles and Themes (styles and Themes)

A style is a collection of view or form (window) properties that contains the specified appearance and formatting. A style can specify a number of attributes, such as height, padding, font color, font size, background color, and so on. A style is defined in an XML resource file and is distinguished from the layout specified in the XML.

CSS in the Android style and web design share a similar principle that allows you to separate design and content.

For example, by using a style, you can make your layout xml look like this:

<TextView    android:layout_width= "Fill_parent"    android:layout_height= "Wrap_content"     Android:textcolor= "#00FF00"    android:typeface= "monospace"    android:text= "@string/hello"/>

And, it can turn out like this:

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

All properties associated to the style have been deleted in the layout XML and defined in a style called "Codefont". It is applied through a style attribute. In the following sections, you will see how to define a style.

A theme (Theme) is also a style that is applied to all activity or application, not to individual view controls (like the example above). When a style is applied as a theme, each activity or view control in the application will apply each of the style attributes it supports. For example, you can use the same codefont style as a theme on the activity, and all the internal fonts in the activity will become Codefont style font styles into green, equal-width fonts.

Define a style type style

To create some styles, you can save them in an XML file under the Res/values/folder under your project. The name of the XML file is arbitrary, but the extension must be. xml and stored under the Res/values/folder.

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

For each style you create, add a <style> element, and you need a Name property that identifies uniqueness and is required. Add the <item> element to your style attributes, use a name attribute declared in the style attribute, and a value property, both of which are required. The Value property of <item> can be a keyword string, a 16-binary color description, a reference to a different resource type, or a value that is dependent on other style attributes. Here is a simple example of the style file content:

<?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>

Each child node of a <resources> element is converted to a program resource object at compile time. It can be referenced by the value of the Name property of the <style> element (value). This example style can be referenced in the XML layout, such as "@style/codefont" (as shown in the example above).

The Parent property in the <style> element is optional and points to the resource ID in one of the other styles, which can inherit some properties from this style. If appropriate, you can override (override) the inherited property.

Remember that a style that you want to use in activity or application is defined in the XML file, and all view controls have the same style. A style, such as the one defined above, can be used as a single view control for a style application or as a theme on all activity or application. How to apply a single view or as the subject of the app, we'll discuss later.

Android Chinese Translation-styles and themes (styles and themes)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.