Android style Design)

Source: Internet
Author: User

Android style design is an important feature because it can personalize the widgets in applications. The style design is as follows:


Use XML resources to define styles in Android Projects
A single Android project can define multiple styles
Let the widget apply one of the styles
The style Function of Android is mainly intended for widgets. The style is to be applied to Widgets. In addition, Android provides the theme function to apply styles in a wider range.

The following is an example of a style definition:

Create a new file style. xml in the/res/values/directory. The edit content is as follows:
[Html] <? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<Style name = "myText">
<Item name = "android: textSize"> 18sp </item>
<Item name = "android: textColor"> #00FF00 </item>
</Style>
<Style name = "myButton">
<Item name = "android: background"> #00 BFFF </item>
</Style>
</Resources>
<? Xml version = "1.0" encoding = "UTF-8"?>
<Resources>
<Style name = "myText">
<Item name = "android: textSize"> 18sp </item>
<Item name = "android: textColor"> #00FF00 </item>
</Style>
<Style name = "myButton">
<Item name = "android: background"> #00 BFFF </item>
</Style>
</Resources>

Style. xml syntax description:


In the <resource> label definition resource project, the <style> label is used to define the style resource;
<Style> the name attribute defines the style name, which is applied by the widget;
<Item> the tag defines the content of this style;
TextSize -- font size
TextColor -- font color
Background -- background
For more information, see Android Reference
After the style is defined, widgets can be applied.

It is easy to apply the defined style to Widgets. You only need to add the defined style name to the widget project attribute in main. XML. Edit main. XML:
[Html] <? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical">
 
<TextView
Style = "@ style/myText"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello"/>
 
<Button
Android: id = "@ + id/btn"
Style = "@ style/myButton"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"/>
 
</LinearLayout>
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical">

<TextView
Style = "@ style/myText"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello"/>

<Button
Android: id = "@ + id/btn"
Style = "@ style/myButton"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"/>

</LinearLayout>

Program Execution result:

 





From Young's column

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.