Android settings transparent, translucent and other effects

Source: Internet
Author: User
Tags set background

There are about three ways to set the transparency effect1, using the Android system's transparent effect Java code android:background= "@android: Color/transparent"For example, set the 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, using ARGB to control the Java code translucency<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 toV.getbackground (). Setalpha (100);//0~255 Transparency ValueAndroid forms transparent, dark and so on settings tricks set Transparency (this is the transparency of the form itself, non-background)1Windowmanager.layoutparams LP=GetWindow (). GetAttributes ();2Lp.alpha=0.3f;3GetWindow (). SetAttributes (LP); Alpha is between 0.0f and 1.0f. 1.0 completely opaque, 0. 0f completely transparent set the dark degreeWindowmanager.layoutparams LP=GetWindow (). GetAttributes ();Lp.dimamount=0.5f;GetWindow (). SetAttributes (LP);GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_DIM_BEHIND);d imamount between 0.0f and 1.0f,0.0f is completely dark, 1. 0f all Dark set background blurGetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_BLUR_BEHIND,WindowManager.LayoutParams.FLAG_BLUR_BEHIND); settings for transparent, translucent effects of the same active activity as the Dialog dialog box Transparentres/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>//Note://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 settingmanifest.xml<Activity Android:name=". Transparentactivity "Android:theme= "@style/transparent" > </activity>Java Code Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); SetTheme (r.style.transparent); Setcontentview (r.layout.transparent); The configuration ends.

Android settings transparent, translucent 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.