Styles and Themes in Android

Source: Internet
Author: User

The inevitable use of styles and themes in Android apps, styles that specify the height, font, font color, background of a general specified view, and the sample recommendation in Android are defined in the Style.xml file. A theme is also a style, but it is applied throughout the activity or application, not just the view. The two are basically the same, the biggest difference is the scope of the function is different. The style is for a single view control, a wider range of topics, or just start writing.

custom styles and Themes

The simplest new Android project will have a textview content of HelloWorld:

   <textview       android:layout_width= "wrap_content"       android:layout_height= "wrap_content"        android:text = "@string/hello_world"/>

At this point we can write these attributes in the new style in/res/values/styles.xml:

    <style name= "Content_mystyle" >        <item name= "Android:layout_width" >wrap_content</item>        <item name= "Android:layout_height" >wrap_content</item>        <item name= "Android:textcolor" ># 3a5fcd</item>        <item name= "android:textsize" >20sp</item>    </style>

  Call:

   <textview        style= "@style/content_mystyle"        android:text= "@string/hello_world"/>

The effect is as follows:

Custom theme:

  <style name= "Theme_mytheme" >        <item name= "Android:background" > #080808 </item>    </style >

Called in application:

  <application        android:allowbackup= "true"        android:icon= "@drawable/ic_launcher"        android:label= "@ String/app_name "        android:theme=" @style/theme_mytheme "         ;

The effect is as follows:

 

system styles and theme extensions

Redefine the activity, the inside only need a ProgressBar on the line, the above style is common, if like dialog box, progress bar This, some of the style itself is not very clear, go directly to the SDK to find to rewrite:

If The result is to modify a single style directly to Styles.xml to find, modify the theme to find in the themes can:

The original style of ProgressBar is as follows:

  <style name= "Widget.progressbar" >        <item name= "android:indeterminateonly" >true</item>        <item name= "android:indeterminatedrawable" > @android:d rawable/progress_medium_white</item>        < Item Name= "Android:indeterminatebehavior" >repeat</item>        <item name= "Android: Indeterminateduration ">3500</item>        <item name=" Android:minwidth ">48dip</item>        < Item Name= "Android:maxwidth" >48dip</item>        <item name= "Android:minheight" >48dip</item>        <item name= "android:maxheight" >48dip</item>    </style>

Rewrite:

<style name= "Progressbar_mystyle" >        <item name= "android:indeterminateonly" >true</item>        <item name= "android:indeterminatedrawable" > @drawable/progress_medium_white</item>        <item name= "Android:indeterminatebehavior" >repeat</item>        <item name= "Android:indeterminateduration" > 3500</item>        <item name= "android:minwidth" >60dip</item>        <item name= "Android:maxwidth ">60dip</item>        <item name=" android:minheight ">60dip</item>        <item name=" Android: MaxHeight ">60dip</item>    </style>

  Copy the progress_medium_white over and rewrite it:

The code is as follows:

<animated-rotate xmlns:android= "http://schemas.android.com/apk/res/android"    android:drawable= "@drawable/ Ic_launcher "    android:pivotx=" 50% "    android:pivoty=" 50% "/>

Called in the layout

    <progressbar         style= "@style/progressbar_mystyle"        android:layout_width= "Wrap_content"        android: layout_height= "Wrap_content"/>

The effect is as follows:

The theme is very simple, defined two themes, full screen no title:

    <style name= "Test_notitlebar" >        <item name= "Android:windowfullscreen" >true</item>        < Item Name= "Android:background" > #FF1493 </item>        <item name= "Android:windownotitle" >true</ item>    </style>           <style name= "Test_child_notitlebar" parent= "@style/test_notitlebar" >        <item name= "Android:background" > #FF0000 </item>    </style>

Assign values to the activity's theme as follows:

The weekend to see the blog is promising, we have a good Weekend ~

Styles and Themes in Android

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.