Android app and Activity theme configuration

Source: Internet
Author: User

I. Styles and themes (style and theme)

The 1.1 style is a collection of properties that specify the appearance and format of views and Windows. Styles can specify properties such as text, font and size, background color, and so on. Like what:

1 <Resources>2 3     <stylename= "Customfont">4 <item name= "Android:layout_width" >match_parent</item>5 <item name= "Android:layout_height" >wrap_content</item>6 <item name= "Android:textcolor" > #d05050 </item>7 <item name= "android:textsize" >16sp</item>8 <item name= "android:gravity" >center</item>9     </style>Ten  One </Resources>

  Styles are used in the TextView control:

1 < TextView 2         Android:id = "@+id/show_activity_id" 3         style= "@style/customfont"4        android:text= "Hello" />

1.2 Style inheritance

The style can inherit a current style through the Paren property, and then modify or add properties. Like what:

1 <Resources>2     3     <stylename= "Customfont">4 <item name= "Android:layout_width" >match_parent</item>5 <item name= "Android:layout_height" >wrap_content</item>6 <item name= "android:textsize" >16sp</item>7 <item name= "android:gravity" >center</item>8     </style>9     Ten     <stylename= "Customfontcolor"Parent= "Customfont"> One <item name= "Android:textcolor" > #d05050 </item> A     </style> -  - </Resources>

Currently, when inheriting from a defined style, you can also not need the parent property, just precede the new style name with the name of the style that will be inherited, and use "." Between the names. Separated. Like what:

1 <Resources>2 3     <stylename= "Customfont.customfontcolor">4 <item name= "Android:textcolor" > #d05050 </item>5     </style>6 7 </Resources>

  1.2 Setting themes for activity or application

To set the theme for Activity or application, in the Androidmanfest.xml file, in the <Activity> (or <Application>) tab, set up Android: The Theme property. Like what:

1 <Application2     Android:allowbackup= "true"3 Android:icon= "@mipmap/ic_launcher"4 Android:label= "@string/app_name"5 Android:supportsrtl= "true"6 Android:theme= "@style/apptheme">7 8     <Activity9         Android:name=". Activity.secondactivity "Ten Android:launchmode= "Singletop" One Android:theme= "@style/customttheme"/> A  - </Application>

  If the inherited system theme does not meet the requirements, you can also inherit the theme, modify or add attributes, as follows:

< Resources >    <  name= "Customttheme"  parent= "@style/apptheme">         <item name= "Android:colorbackground" > #666 </item>     </ style > </ Resources >

Android app and Activity theme configuration

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.