Android Shape Control Landscaping Implementation code _android

Source: Internet
Author: User

If you're not satisfied with the UI controls that come with your Android system, you can try a custom control, and we'll take the button as an example, a long time ago Android123 wrote the Android button button control beautification method that mentions the selector constructs of XML. Of course, in addition to using images like Drawable, the Android web today talks about customizing the shape shapes, and supports the following properties on the button control Android shape, gradient, stroke, corners, and so on.

Let's take the current system button selector as an example:

 <shape>
  <gradient
  android:startcolor= "#ff8c00"
  android:endcolor= "#FFFFFF"
  android: angle= "270"/>
  <stroke
  android:width= "2DP"
  android:color= "#dcdcdc"/>
  android:radius= "2DP"/>
  <padding
  android:left= "10DP"
  android:top= "10DP"
  Android : right= "10DP"
  android:bottom= "10DP"/>
 </shape>

For the above, the definition of this shape, respectively, is a gradient, in gradient the StartColor property is the beginning of the color, endcolor for the gradient end of the color, the following angle is the angle. Next is stroke can be understood as the edge, corners for the corner here Radius property is radius, and finally relative position attribute padding.

For a button The complete definition can be thought

 <?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:startcolor=" #ff8c00 "an
  Droid:endcolor= "#FFFFFF" android:angle= "270"/> <stroke android:width= "2DP" android:color= "#dcdcdc"/>
  <corners android:radius= "2DP"/> <padding android:left= "10DP" android:top= "10DP" android:right= "10DP" android:bottom= "10DP"/> </shape> </item> <item android:state_focused= "true" > <shape> & Lt;gradient android:startcolor= "#ffc2b7" android:endcolor= "#ffc2b7" android:angle= "270"/> <stroke Android : width= "2DP" android:color= "#dcdcdc"/> <corners android:radius= "2DP"/> <padding android:left= "10DP 
 "Android:top=" 10DP "android:right=" 10DP "android:bottom=" 10DP "/> </shape> </item> <item> <shape> <gradient andRoid:startcolor= "#ff9d77" android:endcolor= "#ff9d77" android:angle= "270"/> <stroke android:width= "2DP" an Droid:color= "#fad3cf"/> <corners android:radius= "2DP"/> <padding android:left= "10DP" android:top= " 10DP "android:right=" 10DP "android:bottom=" 10DP "/> </shape> </item> </selector>

Note that Android123 tips, the difference between the above several item is mainly reflected in state_pressed press or state_focused gain focus, when to determine what type of display, and there is no state_xxx attributes of the item can be seen as normal state.

The above is to beautify the shape of the Android control data collation, the need for students to refer to.

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.