Implementation mode one (using system transparent style)
By configuring the activity's style to implement, in Androidmanifest.xml find the activity to achieve transparency, add the following code in the activity configuration to set the activity as transparent style, However, this way of implementation can only achieve a purely transparent style, unable to adjust the transparency, so this implementation has some limitations, but this approach is simple to implement.
Android:theme= "@android: Style/theme.translucent"
<activity android:name= "cn.sunzn.transact.MainActivity" android:label= "@string/app_name" Android:theme= "@android: Style/theme.translucent" > <intent-filter> <action android:name= " Android.intent.action.MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/> < /intent-filter> </activity>
Implementation mode two (using custom transparent styles)
The implementation of this approach also configures the Activity's style, but the style here is our custom. The specific implementation process is as follows:
1 Add a transparent color value under the Res/values/color.xml file, where the color parameter is a two-digit unit, the first two digits are transparency, and each two-bit pair is a 16-color number, and the example is white.
<?xml version= "1.0" encoding= "Utf-8"?><resources> <color name= "Translucent_background" ># 80000000</color></resources>
2 Add a custom style to the Res/values/styles.xml file, as shown in the code below.
<!--item Name= "Android:windowbackground" sets the background transparency and its color value--><!--item name= "Android:windowistranslucent" sets whether the current activity is transparent--><!--item Name= "Android:windowanimationstyle" to set the current activity in and out mode--><style Name= "Translucent" > <item name= "Android:windowbackground" > @color/translucent_background</item > <item name= "android:windowistranslucent" >true</item> <item name= "Android: Windowanimationstyle "> @android:style/animation.translucent</item></style>
3 in Androidmanifest.xml find the activity to achieve transparency, configure its properties in the activity that you want to achieve transparency, code as follows, or call SetTheme (R.style) in the activity's Oncreat () method. Translucent) to achieve.
<activity android:name= "cn.sunzn.transact.MainActivity" android:label= "@string/app_name" Android:theme= "@style/translucent" > <intent-filter> <action android:name= " Android.intent.action.MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/> < /intent-filter></activity>
Transparent performance for Activity with Android programming