Android style and theme settings

Source: Internet
Author: User
Tags xml attribute

How to Set styles in the android application, including style definitions, single view settings, global style settings, and style inheritance relationships. 1. style definition android styles are defined in res/values/style. in the xml file, similar to the style defined in a css file in the front-end of the web, but the style of android. xml is automatically loaded without manual import or link. Currently, I do not know whether android can or how to define multiple style files. [Xml] <span style = "background-color: rgb (255,255,255);"> <! -- Global Font style --> <style name = "DefaultFontStyle"> <item name = "android: textSize"> 18px </item> <item name = "android: textColor "> # 0000CC </item> </style> <! -- Global background color --> <style name = "DefaultBgColor" parent = "@ style/DefaultFontStyle"> <item name = "android: background "> # F2F2F2 </item> </style> <! -- Global style --> <style name = "DefaultStyle" parent = "@ style/DefaultBgColor"> </style> </span>. the style definition of android is completed through the style label, and different attribute values B are set by adding the item element. the style can be inherited by setting the parent. The above DefaultBgColor inherits from DefaultFontStyle, and DefaultStyle inherits from DefaultBgColor. In this way, DefaultStyle has the font size, color, and background color attributes. C. the theme style of android is the same as that of General styles, but it is different when referenced. The following describes how to set a style for a single view, such as TextView, set the style as follows [xml] <span style = "background-color: rgb (255,255,255);"> <TextView android: layout_width = "match_parent" android: layout_height = "wrap_content" android: text = "What do I do:" android: textSize = "18px" android: textColor = "# 0000CC"/> </span> You can also reference the style defined in the first part, see [xml] <span style = "background-color: rgb (255,255,255);"> <TextView android: layou T_width = "match_parent" android: layout_height = "wrap_content" android: text = "What am I doing: "style =" @ style/DefaultStyle "/> </span> sets the style attribute of the view for style calling. We recommend that you use this method to separate the style from the layout. Other views and viewGroup settings are the same. For more attributes of a single view, see the http://developer.android.com/reference/android/R.styleable.html#View or a specific view's sdk documentation xml attribute. 3. In web Front-end programming, you can use [html] <span style = "background-color: rgb (255,255,255);"> body {background: # cce8cf; color: #000; font-family: verververdana, tahoma; font-size: 18px; padding: 1px 2px 0 2px; counter-reset: section ;} </span> set a global style [html] <span style = "background-color: rgb (25 5,255,255); "> div {margin-top: 10px; margin-bottom: 10px ;}</span> you can set the style of a single tag in android, this global style is called theme. For example, the default font of the entire application is 18px, the color is # 0000CC, and the background color is # F2F2F2. We can use it in AndroidManifest. the android: theme attribute of the application is set in xml as follows: [xml] <span style = "background-color: rgb (255,255,255);"> <application android: theme = "@ style/DefaultStyle"> </span> DefaultStyle is the theme defined in the first part. The theme we mentioned in the first part is the same as the style definition, use andro for reference. Id: theme. The Code [xml] <span style = "background-color: rgb (255,255,255);"> <activity android: name = ". accountManageActivity "android: theme =" @ style/DefaultStyle "> </span> the topic of the activity has some special settings, such as [xml] <span style =" background-color: rgb (255,255,255); "> android: theme =" @ android: style/Theme. dialog "</span> sets the theme for the Dialog box style. You can also set the theme through setTheme (R. id. xx) completed. Next, the problem arises. If an application sets the application topic, activity, and view style, what are the attribute values of each view style ?? 3. style inheritance android styles adopt the same overwrite and inheritance principles as those in css, the principle is the same as that of an object-oriented subclass that overwrites the parent class attribute and inherits the parent class attribute values that are not defined. If a TextView sets its own style, its ViewGroup sets the style, activity sets the topic, and application sets the topic. It first reads the value of its own style, and looks up the first value found for the style that it does not have, that is, the value to be taken. The read order is View's own style.-> attribute values of ViewGroup on the previous layer-> attribute values of ViewGroup on the upper layer->... -> Activity topic. Example: [xml] <span style = "background-color: rgb (255,255,255);"> <! -- Global Font style --> <style name = "DefaultFontStyle"> <item name = "android: textSize"> 18px </item> <item name = "android: textColor "> # 0000CC </item> </style> <! -- Global background color --> <style name = "DefaultBgColor" parent = "@ style/DefaultFontStyle"> <item name = "android: background "> # F2F2F2 </item> </style> <! -- Global style --> <style name = "DefaultStyle" parent = "@ style/DefaultBgColor"> </style> <! -- TextView Font style --> <style name = "TextViewFontStyle"> <item name = "android: textSize "> 20px </item> </style> </span> the application topic is [xml] <span style =" background-color: rgb (255,255,255 ); "> <application android: theme =" @ style/DefaultStyle "> </span> the activity topic is [xml] <span style =" background-color: rgb (255,255,255 ); "> <activity android: name = ". accountManageActivity "android: theme =" @ style/DefaultStyle "> </span> textView style settings: [java] <span style =" background-color: rgb (255,255,255 ); "> <TextView android: layout_width =" match_parent "android: layout_height =" wrap_content "android: text =" What am I doing: "style =" @ style/TextViewFontStyle "/> </span> the final font size of textView is 20px, and the color is subject to 0000CC set in activity.

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.