Android styletheme-based details

Source: Internet
Author: User

Similar to CSS styles, Styles in android are used to define display styles for interface elements. They are a set of one or more view control attributes. For example, you need to define the font color and size.
In CSS, it is defined as follows:
<Style>
. Itcast {COLOR: # 0000CC; font-size: 18px ;}
</Style>
You can use the css style above as follows: <div class = "itcast"> Chuanzhi podcast </div>
You can define a style in Android as follows:
Add the following content to the res/values/styles. xml file: Copy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<Style name = "itcast"> <! -- Define a globally unique name for a style -->
<Item name = "android: textSize"> 18px </item> <! -- The name attribute is the attribute to be held by the View control of the style -->
<Item name = "android: textColor"> # define CC </item>
</Style>
</Resources>

The above android style can be used in the layout file as follows:Copy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"...>
<TextView style = "@ style/itcast"
.../>
</LinearLayout>

<Style> the element has a parent attribute. This attribute allows the current style to inherit a parent style. The current style can inherit the value of the parent style. Of course, if the value of the parent style does not meet your needs, you can modify it as follows:Copy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<Style name = "itcast">
<Item name = "android: textSize"> 18px </item> <! -- The name attribute is the attribute to be held by the View control of the style -->
<Item name = "android: textColor"> # define CC </item>
</Style>
<Style name = "subitcast" parent = "@ style/itcast">
<Item name = "android: textColor"> # FF0000 </item>
</Style>
</Resources>

In android, a topic is used to define the display style for an application. Its definition is the same as that for a style, as shown below:Copy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<Style name = "itcastTheme">
<Item name = "android: windowNoTitle"> true </item> <! -No title.
<Item name = "android: windowFullscreen">? Android: windowNoTitle </item> <! -Full Screen Display (à)
</Style>
</Resources>

Above "? The question mark in android: windowNoTitle is used to reference the resource value defined in the current topic. The following code shows how to set the topic defined above in AndroidManifest. xml:Copy codeThe Code is as follows: <application android: icon = "@ drawable/icon" android: label = "@ string/app_name"
Android: theme = "@ style/itcastTheme">
......
</Application>

In addition to setting a topic in AndroidManifest. xml, you can also set a topic in the Code as follows:
SetTheme (R. style. itcastTheme );
Although styles and themes are basically the same in definition, they are used differently. Styles are used in separate views, such as EditText and TextView. A Topic uses AndroidManifest. the <application> and <activity> in xml are used in the whole application or an Activity. The topic influences the whole application or Activity globally. If an application uses a topic and the view under the application uses a style, the style priority is higher than the topic when the topic conflicts with the style attribute.

In addition, the android system also defines some themes, such as: <activity android: theme = "@ android: style/Theme. dialog ">. This topic makes the Activity look like a Dialog box. If you need to view these topics, you can go to the reference> android --> R. style.

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.