简体   繁体   中英

How to make Translucent Activity

Hellow, I'm trying to create the translucent Activity and define the code in styles.xml but i'm unable to make my activity Translucent. how can i make it translucent can anybody help? my code of styles.xml is posted below.

<resources>

<!-- Base application theme. -->
<style name="TaxiTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="TaxiTheme.NoActionBar.FullScreen" parent="TaxiTheme">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

<style name="TaxiTheme.NoActionBar" parent="TaxiTheme">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

<color name="transparent_color">#129049</color>

<style name="Theme.Transparent" parent="TaxiTheme">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowBackground">@color/transparent_color</item>
    <item name="android:windowIsTranslucent">true</item>
</style>

Apply this theme to the required Activity

<style name="Theme.TransparentInfo" parent="android:Theme">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@color/semiTransparentBlack</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">false</item>
        <item name="android:backgroundDimEnabled">true</item>
    </style>

value for @color/semiTransparentBlack is #00000000

Add the following style In your res/values/styles.xml file (if you don't have one, create it.) Here's a complete file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>

Now apply the style to your activity in the manifest

<activity 
android:name=".MainActivity"
android:theme="@style/Theme.Transparent">
...
</activity>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM