The transparency of the Android settings control

Source: Internet
Author: User

There are several ways to set the transparency of controls such as View,button.

For example, this sets the transparency of the button button1.

1. Can be set in the activity in the background. Here the button1 is set to translucent, then add Button1.getbackground (). Setalpha (128). Setalpha () can be filled in parentheses between 0--255 numbers. The larger the number, the more opaque it is. But if you do, you can't see the preview on the fly, so you can't determine the transparency well enough. The following methods can see the effect after setting, so you can adjust the transparency by seeing the preview.

2. You can also set the Anroid:alpha property of a control by setting it in the layout. Here the button1 is set to translucent and the code is as follows:

1 <button2                 android:layout_width= "Wrap_content"3                 android:layout_ height= "Wrap_content"4                 android:text= "OK"5                 android:id= "@+id/button1"6                 android:alpha= "0.5"7                 />
View Code

The value of Android:alpha is the number between 0~1. The larger the number, the more opaque it is. 1 means completely opaque and 0 is completely transparent.

3. Both of the above methods are from API 11. In other words, API 11 cannot be used in this way. However, you can set the transparency by setting android:background in the layout. The format of the Android:background value is "#AARRGGBB". AA is the transparency, R, G, B is red, green and blue three colors. Each bit is a 16-digit number of 0--f. The greater the number of transparency, the more opaque it is. So if you want to set the opacity to 50% white, you can set the code as follows:

1 <button2                 android:layout_width= "Wrap_content"3                 android:layout_ height= "Wrap_content"4                 android:text= "OK"5                 android:id= "@+id/button1"6                 android:background= "#80ffffff"7                 />
View Code

The control will deform and will be stretched. The workaround is to explicitly set the width and height of the control in the background code. This method is not recommended if you are only setting the transparency of the control.

The transparency of the Android settings control

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.