Setting transparent (two implementations) for transparent/translucent effects of activity _android

Source: Internet
Author: User

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);
}

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.