Android uses shape to define colors, background colors, border colors for different controls

Source: Internet
Author: User
Tags border color

Android uses shape to define colors, background colors, border colors for different controls

The right and bottom border color of the set button is red and the border size is 3DP:

Create a new Buttonstyle.xml file in drawable with the following contents:

<?xml version= "1.0" encoding= "UTF-8"?> <layer-list  xmlns:android= "Http://schemas.android.com/apk/res /android >   <!--box color values--><item>         <shape>               <solid android:color= "#ff0000"/>         </shape>   </item>   <!--body background color value-  <item android:bottom= "3DP" android:right= " 3DP ">        <shape>              <solid android:color=" #ffffff "/>                          <padding android:bottom=" 10DP "                   android:left= "10DP"                  android:right= "10DP"                  android:top= "10DP"/ >       </shape>       </item>  

The button inside the layout file is then set as follows:

<button     android:id= "@+id/button1"     android:layout_width= "Wrap_content"      Android:layout_height= "Wrap_content"     android:text= "Button1"     android:background= "@drawable/buttonstyle"/>  

Use of Android shape
Shape is used for setting shapes, can be used in selector,layout and so on, there are 6 sub-tags, the properties are as follows:

<?xml version= "1.0" encoding= "Utf-8"?> <shape xmlns:android= "Http://schemas.android.com/apk/res/android" > <!--rounded Corners--<Corners Android:radius= "9DP"Android:topleftradius= "2DP"Android:toprightradius= "2DP"Android:bottomleftradius= "2DP"Android:bottomrightradius= "2DP"/><!--Set the fillet radius-<!--gradient-<Gradient Android:startcolor= "@android: Color/white"Android:centercolor= "@android: Color/black"Android:endcolor= "@android: Color/black"Android:uselevel= "true"Android:angle= "45"Android:type= "Radial"Android:centerx= "0"Android:centery= "0"Android:gradientradius= "/>" <!--interval--<padding Android:left= "2DP"Android:top= "2DP"Android:right= "2DP"Android:bottom= "2DP"/><!--All directions--<!--size--<size Android:width= "50DP"Android:height= "50DP"/><!--width and height--<!--filled-in <Solid Android:color= "@android: color/white"/><!--filled colors-<!--strokes-<Stroke Android:width= "2DP"Android:color= "@android: Color/black"Android:dashwidth= "1DP"Android:dashgap= "2DP"/> </shape>

Android uses shape to define colors, background colors, border colors for different controls

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.