How to make Translucent Activity

后端 未结 2 997
忘了有多久
忘了有多久 2020-12-19 13:46

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 a

相关标签:
2条回答
  • 2020-12-19 14:21

    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>
    
    0 讨论(0)
  • 2020-12-19 14:27

    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

    0 讨论(0)
提交回复
热议问题