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.