Describes how to use an XML Resource file to define colors and styles.

Source: Internet
Author: User
1. use an XML Resource file to define colors. this method is highly scalable and easy to modify and share. for example, you can create a color in the values directory. xml 1. use an XML Resource file to define colors. this method is highly scalable and easy to modify and share. for example, you can create a color in the values directory. xml

 
     
  
   #ffb52121
   
 

Defines a color named mycolor. in other places, you can reference mycolor to obtain the color value, as shown in

TextView definition:

Android:textColor="@drawable/mycolor"

2. use an XML Resource file to define a style. define a shape. xml file in res/drawable.

Instance code:

   
         
          
          
              
      
   
 
      
      
      
      
      
      
      
       
      
  
 

Define buttons in the xml of your Activity (such as activity_main.xml)

 

Shape attributes:

Solid

Description: internal filling.

Property: android: color fill color

Size

Description: size.

Attribute:

Android: width android: height

Gradient

Description: gradient.

Attribute:

Android: startColor gradient start color android: endColor gradient end color android: centerColor gradient intermediate color android: angle gradient angle, angle = 0, gradient from left to right, then it turns counter-clockwise. When angle is 90, the gradient changes from top to bottom. Angle must be a multiple of 45 android: type gradient type: linear (linear), radial (radioactive, starting color as the center), sweep (scanning line gradient) android: userLevel: to use the LevelListDrawable object, set it to true. Set true to no gradient, and false to gradient android: grdientRadial gradient radius. this value takes effect only when the type is set to radial. android: relative location of the X-point coordinate of the centerX gradient center android: relative position of the Y coordinate of the centerY gradient Center

Stroke

Description: stroke.

Attribute:

Android: width stroke width android: color stroke color android: dashwidth stroke width when the style is dotted line, when the value is 0 is solid line, when the value is greater than 0 is dotted line android: interval between dashGap when the stroke is a dotted line

Corners

Description: rounded corner.

Attribute:

Android: radius four-angle radius value android: topLeftRadius upper left corner radius value android: topRightRadius upper right corner radius value android: bottomLeftRadius lower right corner radius value android: bottomRightRadius lower left corner radius value

Padding

Description: padding.

Attribute:

Android: left padding android: right padding android: top padding android: bottom padding:

The preceding section details how to use an XML Resource file to define colors and styles. For more information, see other related articles in the first PHP community!

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.