Android shape and selector, androidselector

Source: Internet
Author: User

Android shape and selector, androidselector

1. shape usage example:

<Shape> <! -- Solid --> <solid android: color = "# ff9d77"/> <! -- Gradient --> <gradient android: startColor = "# ff8c00" android: endColor = "# FFFFFF" android: angle = "270"/> <! -- Stroke --> <stroke android: width = "2dp" android: color = "# dcdcdc"/> <! -- Rounded corner --> <corners android: radius = "2dp"/> <padding android: left = "10dp" android: top = "10dp" android: right = "10dp" android: bottom = "10dp"/> </shape>
  • Solid: solid, indicating Filling
  • Gradient: gradient

Android: startColor and android: endColor are the start and end colors respectively. android: angle is the gradient angle, which must be an integer multiple of 45.
In addition, the default gradient mode is android: type = "linear", that is, linear gradient. You can specify the gradient as a radial gradient, android: type = "radial", and the radius must be specified for the radial gradient android: gradientRadius = "50 ".

  • Stroke: stroke

Android: width = "2dp" stroke width, android: color stroke color.
We can also draw the stroke into a dotted line. The setting method is as follows:
Android: dashWidth = "5dp"
Android: dashGap = "3dp"
Android: dashWidth indicates the width of a horizontal line like '-', and android: dashGap indicates the distance between them.

  • Corners: rounded corner

Android: radius is the Radian of an angle. The larger the value is, the closer the angle is.

2. Examples of selector usage:

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_checked="true"           android:drawable="@drawable/enabled_on_pressed" />    <item  android:state_pressed="true"          android:drawable="@drawable/enabled_on_pressed" />    <item           android:drawable="@drawable/disabled_off" />              </selector>

Drawable items can have the following attributes:
Android: drawable = "@ [package:] drawable/drawable_resource"
Android: state_pressed = ["true" | "false"]
Android: state_focused = ["true" | "false"]
Android: state_selected = ["true" | "false"]
Android: state_active = ["true" | "false"]
Android: state_checkable = ["true" | "false"]
Android: state_checked = ["true" | "false"]
Android: state_enabled = ["true" | "false"]
Android: state_window_focused = ["true" | "false"]

The order of items is exquisite. the more detailed the conditions are, the more advanced the conditions should be.

 

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.