Home >Web Front-end >JS Tutorial >A brief discussion on three methods of setting transparency and darkness on Android
This article describes three methods of setting transparency, translucency, and darkness using Android. It has certain reference value. Interested friends can learn about it.
There are roughly three types of settings for transparency effects
1. Use the transparent effect of the android system
Java code
android:background="@android:color/transparent"
For example, set the button
Java code
2. Use ARGB to control
Java code
//半透明 <Button android:background="#e0000000" /> //透明 <Button android:background="#00000000" />
Related tutorials: Java video tutorial
3. Set alpha
Java code
View v = findViewById(R.id.content);//找到你要设透明背景的layout 的id v.getBackground().setAlpha(100);//0~255透明度值
android form transparency, darkness, etc. setting tips
Set transparency (this is the transparency of the form itself, not the background)
WindowManager.LayoutParams lp=getWindow().getAttributes(); lp.alpha=0.3f; getWindow().setAttributes(lp);
alpha is between 0.0f and 1.0f. 1.0 is completely opaque, 0.0f is completely transparent
Set the darkness
WindowManager.LayoutParams lp=getWindow().getAttributes(); lp.dimAmount=0.5f; getWindow().setAttributes(lp); getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dimAmount is between 0.0f and 1.0f, 0.0f is not dark at all, 1.0f is completely dark
Activity’s transparent and translucent effect settings 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> //注意: //color.xml的#5000000前两位是透明的效果参数从00--99(透明--不怎么透明), //后6位是颜色的设置
manifest.xml
<activity android:name=".TransparentActivity" android:theme="@style/Transparent"> </activity>
java code
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTheme(R.style.Transparent); setContentView(R.layout.transparent); }
The above configuration is completed, I hope it will be helpful to you.
Related tutorials: Android video tutorial
The above is the detailed content of A brief discussion on three methods of setting transparency and darkness on Android. For more information, please follow other related articles on the PHP Chinese website!