Android Theme and Style

Source: Internet
Author: User

Each company's app has its own unified characteristics, which involves theme and style, of course, they are not just for this feature exists, want activity into the animation, etc. can be achieved through theme and style, simple and reduce the number of code, skilled use of theme and Style can also make a very cool effect.

What is theme?

The theme is for all the activity in the entire application, or for the specified activity to define the format, which usually changes the appearance of the window format, title, border, etc.

What is a style?

Specifying the font, color, and other properties for each view will undoubtedly add a lot of code and is not conducive to the maintenance of our post-project, so we know that by introducing the style to the web, we can set the elements in HTML through the CSS selector, and in the UI component, We can specify styles by using the Style property.


This is the source code in the theme and style of all styles, here does not describe how to use, only to describe the meaning of the attributes, can achieve what effect, easy to implement in your own app customization!

Window Property
<!--Window attributes --<Item name="Windowbackground"> @drawable/screen_background_selector_dark</Item> <Item name="Windowbackgroundfallback">?attr/colorbackground</Item> <Item name="Windowcliptooutline">false</Item> <Item name="Windowframe"> @null </Item> <Item name="Windownotitle">false</Item> <Item name="Windowfullscreen">false</Item> <Item name="Windowoverscan">false</Item> <Item name="Windowisfloating">false</Item> <Item name="Windowcontentoverlay"> @null </Item> <Item name="Windowshowwallpaper">false</Item> <Item name="Windowtitlestyle"> @style/windowtitle</Item> <Item name="Windowtitlesize"> -dip</Item> <Item name="Windowtitlebackgroundstyle"> @style/windowtitlebackground</Item> <Item name="Windowanimationstyle"> @style/animation.activity</Item> <Item name="Windowsoftinputmode">stateunspecified|adjustunspecified</Item> <Item name="Windowactionbar">false</Item> <Item name="Windowactionmodeoverlay">false</Item> <Item name="Windowcloseontouchoutside">false</Item> <Item name="Windowtranslucentstatus">false</Item> <Item name="Windowtranslucentnavigation">false</Item> <Item name="Windowdrawssystembarbackgrounds">false</Item> <Item name="Statusbarcolor"> @color/black</Item> <Item name="Navigationbarcolor"> @color/black</Item> <Item name="Windowactionbarfullscreendecorlayout"> @layout/screen_action_bar</Item> <Item name="Windowcontenttransitions">false</Item> <Item name="Windowactivitytransitions">false</Item>

The above code is from the source of the Themes.xml, are the properties of window

  • Windowbackground background
  • Windowbackgroundfallback
  • Windowcliptooutline
  • Windowframe Dialog Whether there is a border
  • Windownotitle whether there is a title
  • Whether the Windowfullscreen is full screen
  • Windowoverscan If the form is required to fill the entire screen
  • Whether the windowisfloating is floating above the lower level
  • Windowcontentoverlay Setting Overlay content Background
  • Windowshowwallpaper whether to show wallpaper
  • Windowtitlestyle title bar Style
  • Windowtitlesize form Text Size
  • Windowtitlebackgroundstyle title bar background style
  • Windowanimationstyle the animated style when switching
  • Windowsoftinputmode the form's adaptation when using IME
  • Windowactionbar whether to open Actionbar
  • Windowactionmodeoverlay whether to overwrite action
  • Windowcloseontouchoutside If you click outside again to close
  • Windowtranslucentstatus whether translucent state
  • Windowtranslucentnavigation whether to use semi-transparent navigation
  • Windowdrawssystembarbackgrounds whether to draw the system navigation bar background
  • Statusbarcolor status bar Color
  • Navigationbarcolor Navigation bar Color
  • Windowactionbarfullscreendecorlayout layout when full-screen
  • Windowcontenttransitions whether the content is converted
  • Windowactivitytransitions Activity Time Conversion

The above content is believed that everyone has used, here briefly say Windowanimationstyle, mainly responsible for the activity of the switch animation, here are two forms, one is to set the window animation, one is to set activity animation

 <itemname="@android:windowEnterAnimation">@anim/dialog_enter</item>   <itemname="@android:windowExitAnimation">@anim/dialog_exit</item>
<item  name  = "activityopenenteranimation"  > @anim/activity_ Open_enter</item  > <item  name  = "activityopenexitanimation"  > @anim/ Activity_open_exit</item  > <item  Span class= "Hljs-property" >name  = "activitycloseenteranimation"  > @anim/ Activity_close_enter</item  > <item  name  = "activitycloseexitanimation"  > @anim/activity_close_exit</item ;  

Set up as needed, here's how to animate the activity

    1. Activityopenenteranimation
    2. Activityopenexitanimation
    3. Activitycloseenteranimation
    4. Activitycloseexitanimation

Here, the activity a jumps to activity B as an example, to illustrate the above four, the first a jumps to b,b into the animation; the second a jumps to the b,a disappearing animation; The third a returns to B, the animation of A; Fourth a returns to the animation of the disappearance of b,b, which needs to be said , if you set the animation did not follow the way you think, you need to check whether the two are set animation, which is why I wrote this article.

Of course, there are a lot of code theme.xml, a variety of topics are in here, you might as well use the time to look at, many of them are described above those attributes, here only to see we usually use more.

Style uses

The use of style is relatively simple, you can achieve code cleanliness, reduce a lot of unnecessary things

<stylename="Widget.button"> <Item name="Background"> @drawable/btn_default</Item> <Item name="Focusable">true</Item> <Item name="clickable">true</Item> <Item name="Textappearance">?attr/textappearancesmallinverse</Item> <Item name="TextColor"> @color/primary_text_light</Item> <Item name="Gravity">center_vertical|center_horizontal</Item> </style>

Here is the button we often use, a unified definition of the format, the code is simple, directly using the style attribute to apply it, here is not detailed

Skilled use of theme and style will bring you great benefits, the existence is reasonable, skilled use of tools in hand to improve efficiency, write high-quality code!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Theme and style

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.