Step by Step _android Development Course [37]_ user interface Theme and style

Source: Internet
Author: User

Focus on technology, enjoy life! --qq:804212028
Browse Links: http://blog.csdn.net/y18334702058/article/details/44624305

    • Theme: Theme and style of user interface
      -theme and style are easy to confuse, and the theme style is used to add to application or activity. The style style is used to add to the view control.

Definition of Style:

Locate the project folder: Res/valus/styles,styles.xml This file is a folder specifically designed to define styles. If not, create one yourself.
The code is as follows:

<?xml version= "1.0" encoding= "Utf-8"?><resources>    <style name="Apptheme" parent="Appbasetheme"><item name= "android: Layout_width">fill_parent &l T Item name= "android: Layout_height">wrap_content <item name= "android: TextColor">00FF00     </style></Resources>

Inheritance of styles:

A style that developers should know can inherit the original style of the platform, or they can inherit a custom style. The original style of the inherited platform is as follows

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

Inheriting a custom style simply adds a prefix name to the style's Name property. The prefix name is the name of the custom style, such as the Red style inheritance Codefont style can be written like this:

<style name="CodeFont.Red">    <item name="android:textColor">FF0000</style>

This inheritance can also continue to inherit, big and then inherit their style:

<style name="CodeFont.Red.Big">    <item name="android:textSize">30sp</style>

Use of Style and theme:

//在控件里使用styles样式<TextView    style="@style/CodeFont    android:text="@string/hello" />//在application中使用themes样式<application android:theme="@style/MyTheme">//在activity中使用themes样式<activity android:theme="@style/MyTheme">

What is style and what is theme?

Style: is a collection of one or more formatting attributes that we can use as a unit in a single element of the layout XML. For example, we can define a style to define the font size and color of the text, and then use it in a particular instance of the view element.

Theme: is a collection of one or more formatting attributes that we can use as a unit in all activity in the app (i.e., application) or in an activity.

Let's look at their definition:

<?xml version= "1.0" encoding= "Utf-8"?>   <resources>       <!--define Style --<style name="Mytextstyle" mce_bogus="1"><item name= "android: textSize">20px</Item> <item name= "android: TextColor">EC9237</Item ></style>      <style name="MyTextStyle2" mce_bogus="1"> <item name= "android: textSize">14px</Item> <item name= "android: TextColor">ff7f7c</Item ></style>       <!--definition Theme --     <style name="MyTheme" mce_bogus="1"><item name= "android: Windownotitle">true</item > <item name= "android: textSize">14px</  Item> <item name= "android: TextColor">ffff7f7c </Item></style>  </Resources> 

As can be seen from the above example, the definition of style is basically the same as the definition of theme, except that it is used in different places, and also in the use of some tags: style acts on view,theme acting on application or activity.

Focus on technology, enjoy life! --qq:804212028
Browse Links: http://blog.csdn.net/y18334702058/article/details/44624305

Step by Step _android Development Course [37]_ user interface Theme and style

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.