Shape in Android

Source: Internet
Author: User

Shape can achieve some of the effects you want, for example, sometimes you get the focus on a button and press it to change the image to give the customer a better experience.

Shape can change some properties of these controls. It can be said that you can achieve focus in a small project, press the unified effect and style, and this is super convenient.

Create an XML file under your drawable folder, such as selector. xml

There are several attributes in shape, which are actually very simple:


<Shape>
<Solid Android: color = ""/> Solid property: What color

<Gradient

Android: startcolor = "" gradient property: 1. Start color

Android: endcolor = "2. End color

Android: angle = "90"/> 3. angle: the gradient angle must be a multiple of 45 degrees.

// The gradient is a linear gradient by default. Android: TYPE = "linear ",

// To change to a radial gradient Android: TYPE = "RADIAL", you must specify the radius Android: gradientradius = "30 ".


<Stroke attributes:

Android: width = "3dp" 1. stroke width

Android: dashwidth = "6dp" 2. Horizontal line width
Android: dashgap = "3dp" 3. Distance

Android: color = ""/> 4. Stroke color



<Corners rounded corner attributes:
Android: toprightradius = "20dp" upper right corner
Android: bottomleftradius = "20dp" bottom right corner
Android: topleftradius = "1dp" upper left corner
Android: bottomrightradius = "0dp" lower left corner
/>

<Padding

Android: Left = "10dp"

Android: Top = "10dp"

Android: Right = "10dp"

Android: Bottom = "10dp"/>

</Shape>

Normally in selector. XML, the focus is obtained. When you press it, you can set it to see different effects.

<Selector

<Item Android: state_pressed = "true">

<Shape>

</Shape>

</Item>

<Item Android: state_focused = "true">

<Shape>

</Shape>

</Item>

</Selector>

Okay, that's all. Try it if you want to see the effect ..



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.