Android custom control styles are implemented in XML in the drawable folder

Source: Internet
Author: User

 

Android custom control styles are implemented in XML in the drawable folder
14:37:14 let me talk about two sentences: az313
Add to favorites I want to contribute
The android custom control style is in the XML file in the drawable folder. In the layout file, you can set the control's background attribute to achieve the effect.

I. Common states of controls: Selector nodes are used in XML files. selector can be understood as a state switch. Different styles are switched under different states, and various States are represented by item nodes, the following are some common states (Note: The first item in statelist that matches the current state will be used. Therefore, if the first item does not have any State feature, it will be used every time, which is why the default value must always be at the end and can be used in different States ): 1. Android: state_pressedboolean. "True" indicates that the press is used (for example, when a button is pressed), and "false" indicates that the press is not used. 2. Android: state_focusedboolean. "True" indicates that the focus state is used (for example, the scroll ball/D-pad is used to focus the button); "false" indicates that the focus state is used. 3. Android: state_selectedboolean. "True" indicates that the selected state is used (for example, the tab is opened); "false" indicates that the selected state is used. 4. Android: state_checkableboolean. "True" indicates that the status can be checked; "false" indicates that the status is not checked. (It is only useful for components that can be switched and checked-uncheckable .) 5. Android: state_checkedboolean. "True" indicates that the selected status is used; "false" indicates that the selected status is not used. 6. Android: state_enabledboolean. "True" indicates the available status (can receive touch/click events); "false" indicates the unavailable status. 7. Android: window_focusedboolean. "True" indicates that the application window is used when there is focus (the application is on the foreground); "false" indicates that the focus is used when there is no focus (for example, the notification bar is pulled down or displayed in the dialog box ). 2. Shape attributes: each State (item) corresponds to an effect. shape is used to define the shape. The following are some common attributes of shape: 1. Solid: solid, android: Color specifies the fill color 2. Gradient: gradient Android: startcolor and Android: endcolor respectively indicate the start and end colors. Android: angle indicates the gradient angle, it must be an integer multiple of 45. When angle is 0, the gradient is from left to right. Then it turns counter-clockwise. When angle is 90, it goes from bottom to top. 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", you can also specify the combination of the two, scan the gradient
Android: TYPE = "sweep" 3. Stroke: stroke Android: width = "2dp" stroke width, Android: Color stroke color. We can also set the stroke to a dotted line in the form of Android: dashwidth = "5dp" Android: dashgap = "3dp" Where Android: dashwidth indicates the width of a horizontal line like '-', and Android: dashgap indicates the distance between them. 4. corners: rounded corner Android: radius is the Radian of an angle. The larger the value is, the closer the angle is. We can also set the four angles to different angles by Android: toprightradius = "20dp": Android: bottomleftradius = "20dp": Android: topleftradius = "1dp" upper left corner Android: bottomrightradius = "0dp"
Note that bottomleftradius is in the lower-right corner, rather than in the lower-left corner. 5. panding: the complete definition of a button is as follows: <? XML version = "1.0" encoding = "UTF-8"?> <Selector xmlns: Android = "http://schemas.android.com/apk/res/android"> <item Android: state_pressed = "true"> <shape> <gradient Android: angle = "270" Android: endcolor = "# ffffff" Android: startcolor = "# ff8c00"/> <stroke Android: width = "2dp" Android: color = "# dcdcdc"/> <corners Android: radius = "2dp"/> <padding Android: Bottom = "10dp" Android: Left = "10dp" Android: Right = "10dp" Android: top = "10dp"/> </shape> </item> <item Android: state_focused = "true"> <shape> <gradient Android: angle = "270" Android: endcolor = "# ffc2b7" Android: startcolor = "# ffc2b7"/> <stroke Android: width = "2dp" Android: color = "# dcdcdc"/> <corners Android: radius = "2dp"/> www.2cto.com <padding Android: Bottom = "10dp" Android: Left = "10dp" Android: Right = "10dp" Android: top = "10dp"/> </shape> </item> <shape> <gradient Android: angle = "270" Android: endcolor = "# ff9d77" Android: startcolor = "# ff9d77"/> <stroke Android: width = "2dp" Android: color = "# fad3cf"/> <corners Android: radius = "2dp"/> <padding Android: Bottom = "10dp" Android: Left = "10dp" Android: Right = "10dp" Android: top = "10dp"/> </shape> </item> </selector>
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.