The difference between Theme.xml and Style.xml in Android

Source: Internet
Author: User

One, the same point

Both have the same definition and inherit the same way

<?xml version= "1.0" encoding= "Utf-8"?> <resources> <!--inheritance Method 1, parent through the parent genus The sex is used to inherit the style that Android has already defined such as: parent= "Android:Theme.Dialog" or parent= "@android: Style/theme.dialog" 2, inherit the custom Styl E, you can use parent or. such as <style name= "Parent.child" > View when called style= "@style/parent.child" or <style name= "ch Ild "parent=" @style/parent.child "> view is called when style=" @style/child "or <style name=" child "parent=" parent.          Child "> View style=" @style/child "--<style name=" Mydialog "parent=" Android:Theme.Dialog "> <item name= "Android:windowbackground" > @mipmap/ic_launcher</item> </style> <style N Ame= "Parent" > <item name= "android:textsize" >30sp</item> <item name= "Android:text" >p Arent</item> </style> <!--. Inheritance--<style name= "Parent.child" > <it EM name="Android:text" >child</item> <item name= "Android:textcolor" > #ff00ff </item> </style&gt       ; <!--How the parent inherits--<style name= "child" parent= "@style/parent.child" > <item name= "Android:tex   T ">childs</item> </style> </resources>

  

Two, different points



A), the use of different places


1.Theme is used to set the app's global theme style, affecting the entire app or an activity. 5.0 can allow you to adjust the design of the local style;


1) in Androidmanifest.xml:

<application android:theme= "@android: Style/theme" >      <activity android:theme= "@android: Style/theme" >

  

2) in the activity through the Code settings:
SetTheme (R.style.theme);

Note must be set before Setcontentview () is valid

2.Style is mostly used on view, when you set the style on the view, Layoutinflater reads the style and sets the content to AttributeSet before any individual style. Like what:


android:layout_height= "Wrap_content" android:text= "EditText" style= "@style/title" android:layout_ Width= "Fill_parent" android:id= "@+id/edittext1"/>

(ii) Some properties beginning with window in the R.ATTR definition are valid only for theme.


Third), if an application uses theme, and the view used in the application also uses a style, the style takes precedence over the theme when theme conflicts with style style.

The difference between Theme.xml and Style.xml in Android

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.