[Android custom control] button style Customization

Source: Internet
Author: User

Button is one of the longest and most common controls. Attribute features are nothing to say, so we define the button style to achieve the various beautiful button effects we see.

To customize a style, there are two methods:

First, the common usage is shown in Figure 9 (. 9), which is familiar with android Application Development and is often used.

The second is: vector images are drawn by share. This is relatively inefficient. For button style changes, there are not many examples.

 

For more information, see Figure 9. The figure 9 tool is available in the android sdk package. You can try it.

 

 

Area drawn in L: the vertical area used for stretching.

Area drawn in T: the horizontal area used for stretching.

Drawn in the R area: used to display the vertical range of the foreground.

Drawn in Area B: used to display the horizontal range of the foreground.

 

Red box area: indicates the area to be stretched vertically. That is to say, when the image needs to be stretched vertically, it only specifies the red area to be stretched. Other areas are not stretched vertically.

Green Box area: indicates the area to be horizontally stretched. That is to say, when the image needs to be horizontally stretched, it only specifies the green area to be stretched. Other areas are not horizontally stretched.

Obviously, the red and green areas are horizontally stretched and vertically stretched.


 

Blue area: the vertical range of the foreground. That is, the top of the foreground can be displayed, and the bottom can be displayed.

Yellow area: indicates the horizontal range that the foreground can display. That is, the leftmost area of the foreground is displayed, and the rightmost area is displayed.

Intersection of blue and yellow: the area where the entire foreground is displayed. A region is a rectangle. Blue specifies the upper and lower boundary, and yellow specifies the left and right boundary. Of course, the two define a rectangle.

 

Now, go to the topic,

 

(A) begin.

(B) write the image using the x selector bg_button_select.xml.

 

       
        
         
      
    
   
  
  
(C) Add the Button control definition in layout/main. xml. Background attributes can be used for buttons.

 

 

 


Vector steps are similar.

 

The first step is to use xml to define a rounded rectangle, with the solid line of the peripheral contour and the gradient of inner fill.

 

   
      
          
               
               
             
     
    
        
       
         
             
              
             
     
    
        
      
  

 

 

Step 2 Write a selector
bg_button_select.xml
Part 3: reference in button
android:background="@drawable/bg_button_select"

This is simple. Try it all.

 

 


 

 

 

 

 

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.