Transparent performance for Activity with Android programming

Source: Internet
Author: User

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

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.