Use shape in Android to define Display Properties of controls

Source: Internet
Author: User

See http://www.bkjia.com/kf/201110/107462.html

In Android, the display effect of default controls is often not very beautiful. We can create an XML file under drawable, which contains the shape label and its related attributes. For example, you can set a LinearLayout border, fill color, and rounded corner effect in this way.

 

For example, in the following code (today_but_selector.xml ):

<? Xml version = "1.0" encoding = "UTF-8"?>
<Selector xmlns: android = "http://schemas.android.com/apk/res/android">
<Item android: state_pressed = "true">
<Shape>
<! -- Rounded corner -->
<Corners android: radius = "5dp"/>
<Solid android: color = "#888800"/>
</Shape>
</Item>
<Item>
<Shape>
<Solid android: color = "#333333"/>
<Corners android: radius = "5dp"/>
<Padding android: left = "10dp" android: top = "10dp"
Android: right = "10dp" android: bottom = "10dp"/>
</Shape>
</Item>
</Selector>

This xml file can be used as follows. For example, the Button is defined:

<Button android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" android: text = "today"
Android: background = "@ drawable/today_but_selector" android: textColor = "# ffffff"/>

The displayed buttons are as follows:

(1) Under normal circumstances:

 

(2) Press:

 

From: yangzhenyu

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.