[Android] style and theme

Source: Internet
Author: User

I. Style

1. style is for the form Element level. It changes the style of the specified control or layout.

2. styles are inherited and overwrite

3. Style definition, defined in RES/styles. xml

Themes. XML and style. XML (in the system source code frameworks \ base \ core \ res \ values \) contains many styles defined by the system. We recommend that you select an appropriate style and then inherit and modify it.

<?xml version="1.0" encoding="UTF-8"?> <resources>  <style name="TextView">   <item name="android:textSize">18sp</item>   <item name="android:textColor">#008</item>   <item name="android:shadowColor">@android:color/black</item>   <item name="android:shadowRadius">2.0</item>  </style>     <style name="EditText">   <item name="android:shadowColor">@android:color/black</item>   <item name="android:shadowRadius">1.0</item>   <item name="android:background">@android:drawable/btn_default</item>   <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>  </style>        <style name="Button">         <item name="android:background">@android:drawable/edit_text</item>         <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>     </style> </resources>

 

Ii. Theme

1. Theme Changes the form style at the form level;

2. Define the positions and methods in the same way as the style, all in RES/styles. XML files can also be defined in RES/theme. in XML files, the difference is that theme's item names are fixed and their values are variable.

<?xml version="1.0" encoding="utf-8"?><resources><style name="CustomTheme">    <!-- Window attributes -->    <item name="windowBackground">@android:drawable/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:drawable/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></resources>

 

Use, Main. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Orientation = "vertical" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <textview Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "@ string/Hello" style = "@ style/textview"/> <edittext Android: id = "@ + ID/edittext01" Android: layout_height = "wrap_content" style = "@ style/edittext" Android: layout_width = "fill_parent" Android: TEXT = "edittext similar to button"> </edittext> <edittext Android: Id = "@ + ID/edittext02" Android: layout_height = "wrap_content" Android: layout_width = "fill_parent" Android: text = "normal edittext"> </edittext> <button Android: Id = "@ + ID/button01" Android: layout_height = "wrap_content" style = "@ style/button" Android: layout_width = "fill_parent" Android: text = "button similar to edittext"> </button> </linearlayout>
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.