Method One :
Set up Styles.xml under Res/values folder:
Copy Code code as follows:
<?xml version= "1.0″encoding=" utf-8″?>
<style name= "Translucent" >
<item name= "Android:windowbackground" > @color/translucent_background</item>
<item name= "Android:windowistranslucent" >true</item>
</style>
Under this folder in the Create file Colors.xml
Copy Code code as follows:
<?xml version= "1.0″encoding=" utf-8″?>
<RESOURCES>
<color name= "Translucent_background" > #60000000 </color>
</RESOURCES>
With this write setting, you have to tell the activity to use this write setting.
Androidmanifest.xml to find the activity to eject, join theme:
Android:theme= "@style/translucent"
Oh, yes, it's really transparent. But the problem comes again, the button in the layout is not transparent. What if it makes them transparent or translucent? You have to set the window properties.
Copy Code code as follows:
Window Window=getwindow ();
Windowmanager.layoutparams wl = Window.getattributes ();
wl.flags=windowmanager.layoutparams.flag_keep_screen_on;
wl.alpha=0.6f; This sentence is to set the window in the transparency of the Kong pieces. 0.0 fully transparent. 1.0 opaque.
Window.setattributes (WL);
Method Two:
Today, try to do the effect of translucent activity, made to find after the complex! Very simple words can be achieved, not much said, paste code!
Res/values/styles.xml
Copy Code code as follows:
<resources>
<style name= "Transparent
">
<item name= "Android:windowbackground" > @color/transparent_background</item>
<item name= "Android:windownotitle" >true</item>
<item name= "Android:windowistranslucent" >true</item>
<item name= "Android:windowanimationstyle" >@+android:style/Animation.Translucent</item>
</style>
</resources>
Res/values/color.xml
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<color name= "Transparent_background" > #50000000 </color>
</resources>
Note: The first two bits of the color.xml #5000000 are transparent effect parameters from 00--99 (transparent-not transparent), and the latter 6 bits are the color settings
Manifest.xml
Copy Code code as follows:
<activity android:name= ". Transparentactivity "Android:theme=" @style/transparent ">
</activity>
Java code
Copy Code code as follows:
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Settheme (r.style.transparent);
Setcontentview (r.layout.transparent);
}