javaandroid

How to make a view transparent in android?


I'm doing some UI designing for class on an open source project. I'm trying to make the appbar and tabs of this tablayout transparent but no matter what I do they remain white. If it were transparent the background would be able to be seen but i get this white instead. I have tried-

  1. changing the xml values in the mainfragments xml to transparent
  2. changing the colors.xml values to transparent (all of them because i wanted to be sure)
  3. changing and even removing the "light theme" and "dark theme" values in styles.xml and removing the app theme line in the android manifest android:theme="@style/AppTheme.FullScreen.Light" Am I missing something else that i can try? I would be very thankful for any suggestions.

Solution

  • in style.xml

    <?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>
    

    in color.xml value @color/transparent is the color value #00000000

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