The mobile phone screen is too small, and the translucent effect is often used to increase the visible range. We will share with you the following translucent implementation methods!
The following is an example of the effect of translucent custom Activity:
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>
Note: For color. xml #5000000, the first two parameters are transparent, from 00 to ff (transparent-not transparent), and the last six parameters are set colors.
Manifest. xml
<activity android:name=".TransparentActivity"android:theme="@style/Transparent" />
Java code
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTheme(R.style.Transparent); setContentView(R.layout.transparent); }
The following is an example of the effect of using the system topic to achieve Activity Translucent:
Android provides the built-in Theme (android: style/Theme. Translucent) for transparent effects. To achieve transparent effects, you only need to set the Theme for the Activity.
To achieve a Translucent effect, you only need to inherit android: style/Theme. Translucent and rewrite it.
Inherit android: style/Theme. Translucent and rewrite:
<?xml version=”1.0″ encoding=”utf-8″?><resources><style name=”Theme.Translucent” parent=”android:style/Theme.Translucent”><item name=”android:windowBackground”>@color/translucent_background</item><item name=”android:colorForeground”>#fff</item></style></resources>
This topic is used in AndroidMainfest. xml:
<activity android:name=”.Translucent” android:label=”@string/app_name”android:theme=”@style/Theme.Translucent”><intent-filter><action android:name=”android.intent.action.MAIN” /><category android:name=”android.intent.category.LAUNCHER” /></intent-filter></activity>
The following is an example of a translucent View:
The background of a Button or ImageButton is transparent or translucent.
Translucent: <Button android: background = "# e0000000".../>
Transparency: <Button android: background = "#00000000".../>
The color and opacity (alpha) values are expressed in hexadecimal notation. The value range of any color is 0 to 255 (00 to ff ). For alpha, 00 indicates completely transparent, and ff indicates completely opaque. The expression order is "aabbggrr", where "aa = alpha" (00 to ff); "bb = blue" (00 to ff ); "gg = green" (00 to ff); "rr = red" (00 to ff ). For example, if you want to apply a blue opacity of 50% to a stack, specify the following value: 7fff0000
Set the background image transparency (ultra-simple)
Java code
View v = findViewById (R. id. content); // locate the id of layout where you want to set a transparent background
V. getBackground (). setAlpha (100); // 0 ~ 255 transparency Value