The difference and use of Android themes and styles-style and theme

Source: Internet
Author: User

The project often use style and theme, but never consider their differences, will only copy to copy to, and sometimes confused, in order to completely farewell confusion, now the difference between the two and use summed up, for themselves and everyone reference

I. Scope

Theme is for the form level and changes the form style.

Style is for the level of the form element, changing the styles of the specified control or layout

Two. How to use

Theme

1. Create a themes.xml or Styles.xml file under Res\values\

2. Add <resouces> node (root node)

3. Add a custom style

4. (1) in the Androidmanifest.xml file, specify the theme attribute for the activity (recommended)

(2) Call the Settheme function when activity is created (must be called before Setcontentview)

<style name= "Mybubbletheme" parent= "@android: Style/theme.dialog" ><item name= "Android:windowbackground" > @drawable/bubble</item></style>

<activity    android:name= ". Blurthemeactivity "    android:theme=" @style/mybubbletheme "/>

5. The system comes with the theme

Android:theme= "@android: Style/theme.dialog"   //displays an activity as a modal android:theme= "@android: style/ Theme.notitlebar "  //Do not show application title bar Android:theme=" @android: Style/theme.notitlebar.fullscreen "  //Do not display the application title bar, and full Screen android:theme= "@Theme. Light"  //background is white android:theme= "Theme.Light.NoTitleBar"  //white background with no title bar Android:theme = "Theme.Light.NoTitleBar.Fullscreen"  //white background, no title bar, full screen android:theme= "Theme.black  "//Background black android:theme= " Theme.Black.NoTitleBar "  //Black background with no title bar android:theme=" Theme.Black.NoTitleBar.Fullscreen "    //Black background, no title bar, Full screen android:theme= "Theme.wallpaper"  //with System desktop for application background android:theme= "Theme.Wallpaper.NoTitleBar"  // Application background with System desktop, no title bar android:theme= "Theme.Wallpaper.NoTitleBar.Fullscreen"  //with System desktop for application background, no title bar, fullscreen

6. Common Properties

<item name= "Windowbackground" > @android:d rawable/screen_background_dark</item>  <item name= " Windowframe "> @null </item>  <item name=" Windownotitle ">false</item>  <item name=" Windowfullscreen ">false</item>  <item name=" windowisfloating ">false</item>  <item Name= "Windowcontentoverlay" > @android:d rawable/title_bar_shadow</item>  <item name= " Windowtitlestyle "> @android:style/windowtitle</item>  <item name=" Windowtitlesize ">25dip</ item>  <item name= "Windowtitlebackgroundstyle" > @android:style/windowtitlebackground</item>  <item name= "Android:windowanimationstyle" > @android:style/animation.activity</item>  

Style

1. Create a styles.xml file under Res\values\

2. Add <resouces> node (root node)

3. Add a custom style

4. Add a style property to a specific control or layout

<style name= "Mytextstyle" >        <item name= "Android:textcolor" > #FF0000C0 </item>        <item Name= "Android:layout_width" >wrap_content</item>        <item name= "Android:layout_height" >wrap_ Content</item>    </style>
     <textview    style= "@style/mytextstyle"  />


Example:

Many programs just start when the Tips interface, bubble window and frosted glass effect


The code is as follows:

Blurthemeactivity.java

Import Android.app.activity;import Android.os.bundle;import Android.view.windowmanager;public class Blurthemeactivity extends Activity {    @Override    protected void onCreate (Bundle savedinstancestate) {        Super.oncreate (savedinstancestate);        The system blur any windows behind this one.        GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_BLUR_BEHIND,                WindowManager.LayoutParams.FLAG_BLUR_ BEHIND);}    }

Themes.xml

<style name= "Mybubbletheme" parent= "@android: Style/theme.dialog" >        <item name= "Android: Windowbackground "> @drawable/bubble</item>        <item name=" Android:windownotitle ">true</item >    </style>

Androidmanifest.xml

<activity    android:name= ". Blurthemeactivity "    android:theme=" @style/mybubbletheme "/>


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.