Android: style and theme

Source: Internet
Author: User

If the View Interface style needs to be unified, you need to use the style in the android view technology.Style is to write the style content to a separate XML file and place it in RES/values/styles. xml:

 <?  XML version = "1.0" encoding = "UTF-8"  ?>  <  Resources  >     <  Style  Name  = "Itemtitle"  >             <  Item  Name = "Android: textsize"  > 25sp </  Item  >             <  Item  Name  = "Android: textstyle"  > Bold </  Item  >     </  Style  > </  Resources  > 

 

Usage: In the layout File

 

<TextviewStyle = "@ style/itemtitle".../>

In R. Java

Public static final class style {
Public static final int itemtitle = 0x7f050000;
}

 

 

If you want to make a unified style convention on the background color and font of the entire activity, you need to use another technology, theme.

First, write the theme file, which is similar to the style file and placed in the Res/values Directory: (RES/values/theme. XML)

 

 <?  XML version = "1.0" encoding = "UTF-8" ?>  <  Resources  >      <  Color  Name  = "Custom_background_color"  > # Ffffffff </  Color  >      <  Style  Name  = "Rivertheme" Parent  = "Android: theme. Light"  >          <  Item  Name  = "Android: windowbackground"  > @ Color/custom_background_color </  Item  >      </  Style  >  </  Resources > 
 
 

The theme. Light of the system is inherited here. Generally, theme is inherited, so that you do not need to define the default style repeatedly.

This example defines a background color. The background color must be declared separately. You cannot directly write the color value in the item element. A syntax error is prompted.

Reference this theme in the activity specified in the manifest file:

 
<Activity .............
Android: theme = "@ style/rivertheme">

Theme can also be used in the application as a whole...

Reference: http://marshal.easymorse.com/archives/4111

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.