Android Shape and Selector

Source: Internet
Author: User

1.shape Usage Examples:

 <Shape>            <!--Solid -            <SolidAndroid:color= "#ff9d77"/>            <!--Gradient -            <GradientAndroid:startcolor= "#ff8c00"Android:endcolor= "#FFFFFF"Android:angle= "+" />            <!--Strokes -            <StrokeAndroid:width= "2DP"Android:color= "#dcdcdc" />            <!--Rounded Corners -            <CornersAndroid:radius= "2DP" />            <paddingAndroid:left= "10DP"Android:top= "10DP"Android:right= "10DP"Android:bottom= "10DP" />        </Shape>
    • Solid: Filled is the meaning of filling
    • Gradient: Gradient

Android:startcolor and Android:endcolor are start and end colors respectively, Android:angle is the gradient angle and must be an integer multiple of 45.
In addition, the default mode of the gradient is android:type= "linear", that is, linear gradient, you can specify the gradient to radial gradient, android:type= "radial", radial gradient needs to specify the radius android:gradientradius= "50".

    • Stroke: Stroke

Android:width= the width of the "2DP" stroke, android:color the color of the stroke.
We can also make the stroke into a dashed form, set in the following way:
Android:dashwidth= "5DP"
android:dashgap= "3DP"
Where android:dashwidth represents the width of a horizontal line such as '-', android:dashgap represents the distance between them.

    • Corners: Rounded Corners

The Android:radius is the radian of the angle, and the larger the value the greater the rounded.

2.selector Usage Examples:

<?XML version= "1.0" encoding= "Utf-8"?><selectorxmlns:android= "Http://schemas.android.com/apk/res/android">    <Itemandroid:state_checked= "true"android:drawable= "@drawable/enabled_on_pressed" />    <Itemandroid:state_pressed= "true"android:drawable= "@drawable/enabled_on_pressed" />    <Itemandroid:drawable= "@drawable/disabled_off" />              </selector>

The following properties can be found in the drawable item:
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 item order is fastidious, and the more detailed the condition is, the earlier it should be placed.

Android shape and selector

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.