简体   繁体   中英

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.

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>

set alpha value in layout XML or dynamically in view to make view transparent.

view.setAlpha(40);

oR add from xml - value between 0 to 1

android:alpha="0.4"

In android Studio res->values->colors.xml

在此处输入图片说明

Step 1 : For selecting color

Step 2 : Changing transparency(you can move left to right for adjusting transparency )

Step 3 : Give this color as views background

<RelativeLayout
        android:id="@+id/top_bar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@color/color_name">

This may help you.

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