Transparency--set transparency, translucency, and other effects

Source: Internet
Author: User
Tags set background

There are about three ways to set the transparency effect.

1, with the Android system transparency effect:

Android:background= "@android: Color/transparent"

For example, the Set button
<button android:background= "@android: Color/transparent"
Android:textcolor= "#ffffff"/>

2, with ARGB to control

Translucent <button android:background= "#e0000000"/>
Transparent <button android:background= "#00000000"/>

3. Set Alpha

View v = Findviewbyid (r.id.content);//
V.getbackground (). Setalpha (100);//0~255 Transparency Value



--------------
Android form transparent, dark degree and other settings skills;;

Set transparency (This is the transparency of the form itself, not the background)
1 Windowmanager.layoutparams Lp=getwindow (). GetAttributes ();
2 lp.alpha=0.3f;
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 ();
2, lp.dimamount=0.5f;
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 transparent
Res/values/styles.xml

<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

<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<color name= "Transparent_background" > #50000000 </color>
</resources>
Attention:
The first two bits of the color.xml #5000000 are transparent effect parameters from 00--99 (transparent-not very transparent),
The post 6 bit is the color setting
Manifest.xml


<activity
Android:name= ". Transparentactivity "
Android:theme= "@style/transparent" >
</activity>

public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
SetTheme (r.style.transparent);
Setcontentview (r.layout.transparent);
}
Configuration ends.

Transparency--set transparency, translucency, and other effects

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.