The following is an example of the effect of translucent custom Activity:
Res/values/styles. xml
<Resources>
<Stylename = "Transparent">
<Itemname = "android: windowBackground"> @ color/transparent_background </item>
<Itemname = "android: windowNoTitle"> true </item>
<Itemname = "android: javaswistranslucent"> true </item>
<Itemname = "android: windowAnimationStyle"> @ + android: style/Animation. Translucent </item>
</Style>
</Resources>
Res/values/color. xml
<? Xmlversion = "1.0" encoding = "UTF-8"?>
<Resources>
<Colorname = "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 in manifest. xml.
<Activityandroid: name = ". TransparentActivity"
Android: theme = "@ style/Transparent"/>
Java code
Publicvoid 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:
<? Xmlversion = "1.0" encoding = "UTF-8"?>
<Resources>
<Stylename = "Theme. Translucent" parent = "android: style/Theme. Translucent">
<Itemname = "android: windowBackground"> @ color/translucent_background </item>
<Itemname = "android: colorForeground"> # fff </item>
</Style>
</Resources>
This topic is used in AndroidMainfest. xml:
<Activityandroid: name = ". Translucent" android: label = "@ string/app_name"
Android: theme = "@ style/Theme. Translucent">
<Intent-filter>
<Actionandroid: name = "android. intent. action. MAIN"/>
<Categoryandroid: 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
Author: liuxian13183