There are about three ways to set the transparency effect
1, with the Android system transparent effect
Java code
Android:background= "@android: Color/transparent"
For example, the Set button
Java code
<button android:background= "@android: Color/transparent"
android:text= "@+id/button01"
Android:id= "@+id/button01"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:textcolor= "#ffffff"/>
2. Use ARGB to control Java code
Translucent <button android:background= "#e0000000"/>
Transparent <button android:background= "#00000000"/> 3, set Alphajava code
View v = Findviewbyid (r.id.content);//Find the ID of the layout you want to set the transparent background
V.getbackground (). Setalpha (100);//0~255 Transparency Value
Android forms transparent, dark and so on settings tricks set Transparency (this is the transparency of the form itself, non-background)
1 |
WindowManager.LayoutParams lp=getWindow().getAttributes(); |
3 |
getWindow().setAttributes(lp); |
Alpha is between 0.0f and 1.0f. 1.0 completely opaque, 0.0f completely transparent
Set Dark degrees
1 |
WindowManager.LayoutParams lp=getWindow().getAttributes(); |
3 |
getWindow().setAttributes(lp); |
4 |
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
Dimamount between 0.0f and 1.0f, 0.0f completely dim, 1.0f full Dark
Set background blur
1 |
getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND, |
2 |
WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
The above settings are also valid for the dialog dialog box
settings for transparent, translucent effects of activity transparentRes/values/styles.xml
1 2 3 4 5 6 7 8 9 10 11 12 |
<resources> <styleName="Transparent"> <itemName="Android:windowbackground"> @color/transparent_background </item> <itemName="Android:windownotitle">true </item>&NBSP;&NBSP; <item name= "android:windowistranslucent" >true</item> &NBSP <item name= "Android:windowanimationstyle" > @+ Android:style/animation.translucent </item >&NBSP;&NBSP; </style >&NBSP;&NBSP; </resources> |
Res/values/color.xml
1 2 3 4 5 6 7 |
<?xml version= "1.0" encoding= "utf-8" ?>&NBSP;&NBSP; <resources>&NBSP;&NBSP; <color name= "Transparent_ Background "> #50000000 </color> </resources>&NBSP;&NBSP; //Note: //color.xml #5000000 The first two bits are transparent effect parameters from 00--99 (transparent-not very transparent), //after 6-bit is the setting of the color |
Manifest.xml
1 2 3 4 |
<activity Android:name=". Transparentactivity " Android:theme="@style/transparent"> </activity> |
Java code
1 2 3 4 5 |
Public void OnCreate(Bundle savedinstancestate) { Super. onCreate(savedinstancestate); SetTheme(R.style. Transparent); Setcontentview(R.layout. Transparent); } |
Configuration ends.
Android settings transparent, translucent, and other effects