Android Learning Essay UI Landscaping (i)---------styles and Themes

Source: Internet
Author: User

1. use of styles and themes

Styles and themes are the same, and are collections of a series of properties that apply to a single control , such as Textview,button, if the object is applied differently. The theme app appears as an attribute in the <application> or <activity> tab of the feature manifest file , such as:

<application theme= "XXX"/>

<activity theme= "XXX"/>

To see a list file:

Here are the two points to be clear:

1, the theme is applied to the application or activity tag, used to set the overall appearance properties of an entire application or an activity .

2. if a theme is specified at the same time , the subject on the Activity tab will prevail .

Androidmanifest.xml

<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "package=" Com.example.day27_uitest "android:versioncode=" 1 "android:versionname=" 1.0 "> &LT;USES-SD K android:minsdkversion= "android:targetsdkversion="/> <application android:allowback Up= "true" android:icon= "@drawable/ic_launcher" android:label= "@string/app_name"android:theme= "@style/apptheme"> <activity android:name= ". Mainactivity "android:label=" @string/app_name "android:theme= "@style/apptheme"> <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> </acti Vity> </application></manifest>

 2, custom style (here I understand: Here style is like css< cascading style sheet, to standardize some of the appearance)

MyStyle. Xml

<Resourcesxmlns:android= "Http://schemas.android.com/apk/res/android">    <!--Base application theme, dependent on API level.       This theme are replaced by Appbasetheme from Res/values-vxx/styles.xml on newer devices.  -    <stylename= "Appbasetheme"Parent= "Theme.AppCompat.Light"><!--Theme customizations available in newer API levels can go in res/values-vxx/styl         Es.xml, while customizations related to Backward-compatibility can go. -</style>    <!--application theme. -    <stylename= "Apptheme"Parent= "Appbasetheme"><!--all customizations, that is, specific to a particular api-level can go.</style>    <!--Customizing a style to an application use the Parent property to specify the style of the current style, either by referencing the system style or by referring to a user-defined style -    <stylename= "Myapptheme"Parent= "Apptheme"><!--All customizations that is not specific to a particular api-level can go here--<item Name= "Android:textcolor" > @android:color/white</item></style>    <!--Customizing a style for the current interface activity, the style defined in acvitity, which is valid for all controls in the interface -    <stylename= "Mymainactivitytheme"Parent= "Myapptheme"><item name= "android:textsize" >10sp</item> <item name= "Android:textcolor" > #00FF00 </ Item></style>    <!--Customizing the style of a control in a layout file create a sub-style using the parent style prefix, but this usage can only refer to user-defined styles and cannot reference system styles. In other words, referencing a system style can only use the Parent property.             If you use a custom style for both the prefix and the parent property, the parental style specified by the parents property will prevail.  -    <stylename= "Mymainactivitytheme.mytextviewstyle" ><item name= "android:textsize" >20sp</item> <item name= "Android:textcolor" > #FF0000 < ;/item></style>    <stylename= "Mymainactivitytheme.mytextviewstyle2"><item name= "android:textsize" >40sp</item> <item name= "Android:textcolor" > #0000FF < /item></style>        <stylename= "Style_mine"><!--ctrl+alt+ down ARROW key to complete line copy--<item name= "Android:layout_width" >wrap_content</item> <item name= "Android:layout_height" >wrap_content</item></style>    </Resources>

In this file: the first and second styles are the system's own style

The third fourth is a custom style with the parent style

The fifth sixth is a custom style with a parent style prefix, which should be noted at this point:

  If you use a custom style for both the prefix and the parent property, the parental style specified by the parents property will prevail.


The seventh is a custom style without any parent style.

Android Learning Essay UI Landscaping (i)---------styles and Themes

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.