Material TabLayout elevation not working
To make the shadow show, you have to set a background on your TabLayout. It can be the same color as your window background (as long as it's a solid color with no alpha).
<android.support.design.widget.TabLayout android:id="@+id/tab_layout" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:elevation="6dp" android:background="@color/white" />
You are supposed to use ToolBar
with TabLayout
. Then you can put them both inside an AppBarLayout
and get a shadow. This only works on Lollipop+.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar style="@style/ToolBarStyle" android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" android:minHeight="@dimen/abc_action_bar_default_height_material"/> <android.support.design.widget.TabLayout android:id="@+id/tab_layout" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" /> </android.support.design.widget.AppBarLayout> <android.support.v4.view.ViewPager android:id="@+id/view_pager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /></LinearLayout>
See http://inthecheesefactory.com/blog/android-design-support-library-codelab/en
You'll need to use CoordinatorLayout as a container layout for your activity and then place your TabLayout right below AppBarLayout.According to Material Design specs you should use
android:elevation="4dp"
elevation and make your TabLayout be a part of AppBarLayout.Also note that elevation will only be visible on v21 (5.0) or higher.