Android themes and styles

Source: Internet
Author: User

Define styles and themes Res/values/style. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Resources> <style name = "mystyle1"> <item name = "Android: textcolor"> # ff0000 </item> <item name = "Android: textsize "> 10sp </item> <item name =" Android: padding "> 5dip </item> </style> <style name =" mystyle2 "parent =" mystyle1 "> <! -- Override the style of the parent class --> <item name = "Android: textsize"> 20sp </item> <item name = "Android: background "> # FFFF00 </item> </style> <style name =" mytheme "> <item name =" Android: background "> @ drawable/ic_launcher </item> <item name =" Android: windownotitle "> true </item> <item name =" Android: windowfullscreen "> true </item> </style> </resources>

Res/values/string. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Resources> <string name = "hello"> Hello world, styleandthemeactivity! </String> <string name = "app_name"> style and topic </string> <string name = "TV"> London Olympics </string> </resources>

Layout file layout/Main. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical"> <textview Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "@ string/TV" style = "@ style/mystyle1"/> <! -- Use style --> <textview Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: TEXT = "@ string/TV" style = "@ style/mystyle2"/> <! -- Use style --> </linearlayout>

Java code:

Import android. app. activity; import android. OS. bundle; public class styleandthemeactivity extends activity {/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancestate) {// set the topic settheme (R. style. mytheme); // The code must be in super. oncreate (savedinstancestate); before/** in androidmanifest. add Android: theme = "@ style/mytheme" to the <Application> element in XML settings. This topic is used by all activities * to add android to the <activity> element: theme = "@ style/mytheme" use this topic for the specified activitie * Subject and style. The difference is that a style is used in a control, the topic is used in an activity or even the whole application */super. oncreate (savedinstancestate); setcontentview (R. layout. main );}}

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.