How to set TabLayout background to transparent

后端 未结 3 1608
故里飘歌
故里飘歌 2021-01-18 18:08

I need to change TabLayout (extending HorizontalScrollView) background to transparent without changing primary color from styles. If I set a background to #00000000 it beco

相关标签:
3条回答
  • 2021-01-18 18:40

    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

    0 讨论(0)
  • 2021-01-18 18:48

    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"
    
    0 讨论(0)
  • 2021-01-18 18:54

    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.

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