[Android] Android advanced UI development series (3)-android style and topic tutorials

Source: Internet
Author: User

 

Tutorial Index

  1. Android drag and drop tutorial
  2. Android plotting (drawables) Tutorial
  3. Android styles and themes tutorial
  4. Live wallpaper tutorial
  5. Homescreen widgets tutorial
  6. Custom views for Android (M m views) Tutorial
  7. Android supports support for different screen sizes (support different screensize) Tutorial
  8. Android animation (animations) Tutorial
  9. Android touch tutorial

 

1. Android styles and themes

1.1 styles)

Android allows you to define the look and feel of an Android Application in an external style file. You can apply the defined style to different views. You can define styles in an XML file and apply these styles to different components. To use XML to define styles, you only need to configure some common attributes. If you need to modify styles in the future, you can modify them in a centralized manner.

You can create an XML file under the/RES/values file of your android project. Note that the root directory of the file must be <resources>. The following example shows how to create a style. xml file in the/RES/XML directory.

<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<Style name = "text">
<Item name = "Android: padding"> 4dip </item>
<Item name = "Android: textappearance">? Android: ATTR/textappearancelarge </item>
<Item name = "Android: textcolor" >#000000 </item>
</Style>
<Style name = "layout">
<Item name = "Android: background"> # c0c0c0 </item>
</Style>
</Resources>

You can apply the defined style to the component (element). For example, you can use the style = "@ style/text" to apply the text style to the text element.

1.2 attributes (attributes)

You can also apply a single attribute to the android style. The following example defines the button style of Android 4.0.

<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: Orientation = "vertical">

<Linearlayout
Style = "? Android: ATTR/buttonbarstyle"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: Orientation = "horizontal">

<Button
Android: Id = "@ + ID/button01"
Style = "? Android: ATTR/buttonbarbuttonstyle"
Android: layout_width = "0dp"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
Android: text = "show"/>

<Button
Android: Id = "@ + ID/button02"
Style = "? Android: ATTR/buttonbarbuttonstyle"
Android: layout_width = "0dp"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
Android: text = "change"/>
</Linearlayout>

<Edittext
Android: Id = "@ + ID/myview"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: EMS = "10">

<Requestfocus/>
</Edittext>

</Linearlayout>

As follows:

1.3 themes)

A topic is a style applied to the entire activity or application compared to a single view. The following example defines a theme that inherits the theme defined by Android.

<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>

<Style name = "mytheme" parent = "Android: theme. Light">
<Item name = "Android: windownotitle"> true </item>
<Item name = "Android: windowbackground"> @ color/translucent_red </item>
<Item name = "Android: listviewstyle"> @ style/mylistview </item>
</Style>

<Style name = "mylistview" parent = "@ Android: style/widget. listview">
<Item name = "Android: listselector"> @ drawable/ic_menu_home </item>
</Style>

</Resources>

 

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.