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