Android Transparent button

Source: Internet
Author: User

1, is the production of 9-patch pictures, so that can match the length of the text content.

2, is to specify the button style background, that is, custom drawable XML file, the benefits do not use the picture to do the background, save space.

Customize the transparent style of the button. Look directly at the code:

Drawable/buttonstyle.xml:

<?xml version="1.0"encoding="Utf-8"? ><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="true"Android:state_pressed="true"> <shape android:shape="Rectangle"> <corners android:radius="8DP"/> <solid android:color="#d35400"></solid> <size android:height="32DP"Android:width="72DP"></size> <padding android:bottom="5DP"android:left="5DP"Android:right="5DP"android:top="5DP"> </padding> </shape> </item> <item android:state_enabled="true"Android:state_pressed="false"> <shape android:shape="Rectangle"> <corners android:radius="8DP"/> <size android:height="32DP"Android:width="72DP"></size> <padding android:bottom="5DP"android:left="5DP"Android:right="5DP"android:top="5DP"></padding> <solid android:color="#88f39c12"></solid> </shape> </item></selector>

See there are 2 item structures, the first is the button pressed state style, the second is the state of the button in normal state, the item structure contains the shape tag, Android commonly used shape to change some styles of the control.

Common Properties in shape:

Solid : Filled means android:color Specifies the color of the fill gradient: the gradient android:startcolor and Android:endcolor are the start and end colors, respectively, Ndroid:an GLE is a gradient angle and must be an integer multiple of 45. In addition, the default mode for the gradient is Android:type="Linear", which is a linear gradient, you can specify that the gradient is a radial gradient, android:type="Radial", radial gradients need to specify a radius android:gradientradius=" -". Stroke: Stroke Android:width="2DP"The width of the stroke, android:color the color of the stroke. We can also make the stroke into a dashed form, set in the following way: Android:dashwidth="5DP"Android:dashgap="3DP"where Android:dashwidth says'-'the width of such a horizontal line, Android:dashgap represents the distance between them.    Corners: Rounded Angle Android:radius is the radian of the angle, the larger the value the more rounded. Size: Set size padding: Set internal spacing

When you set the color in solid, the color is formatted as #+16 transparency +16 color values, such as: 33ffffff,33 is the alpha value, used to set the transparency, the smaller the value, the more transparent. The latter six bits f is the color value expressed in 16 binary. So the simple way to set the transparency is to set the first 2 bits of the color when you set it.

The final effect is as follows:

Android Transparent button

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.