Android settings transparent, translucent and other effects

Source: Internet
Author: User

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

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.