Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set TabLayout background to transparent

Tags:

android

tabs

I need to change TabLayout (extending HorizontalScrollView) background to transparent without changing primary color from styles. If I set a background to #00000000 it becomes primaryColor. If I set alpha to 0 - I get the same behavior.

enter image description here

<android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#00000000"
        android:hapticFeedbackEnabled="true"/>

Is there any way to set background color transparent without changing styles colors?

like image 459
onCreate Avatar asked Sep 03 '15 09:09

onCreate


Video Answer


3 Answers

Use:

 android:background="@android:color/transparent"

also in the AppBarLayout. to remove the shadow to make look better you can remove the elevation of the AppBarlayout with:

 app:elevation="0dp"
like image 75
cri_sys Avatar answered Oct 18 '22 01:10

cri_sys


If you are using <android.support.design.widget.AppBarLayout />, you have to insert your TabLayout outside of it.

<!-- App Bar -->
<android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/app_bar"
            ......
            android:background="@color/app_bar_color"
            app:layout_scrollFlags="scroll|enterAlways" />
    </android.support.design.widget.AppBarLayout>

<!-- Tab Layout -->
<android.support.design.widget.TabLayout
       android:id="@+id/tabs"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:background="@android:color/transparent"
       android:hapticFeedbackEnabled="true"/>

The Result will be like this

like image 5
rarakat Avatar answered Oct 18 '22 03:10

rarakat


Try this

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:alpha="0.3"
    android:background="@android:color/black"
    android:hapticFeedbackEnabled="true"/>

it works for me.

like image 3
Braj Bhushan Singh Avatar answered Oct 18 '22 01:10

Braj Bhushan Singh