How to show tab indicator at the top of tab

I followed this tutorial . I made a simple change that shows TabLayout at the bottom of the screen.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v4.view.ViewPager android:id="@+id/viewpager_landing" android:layout_width="match_parent" android:layout_height="0px" android:layout_weight="1" android:background="@android:color/white" /> <android.support.design.widget.TabLayout android:id="@+id/sliding_tabs_landing" style="@style/MyCustomTabLayout" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabMode="fixed" /> </LinearLayout> 

enter image description here

Problem: -

TabIndicator shows good work at the bottom of the screen. Now I want to show that TabIndicator at the top of the tab, not the bottom. Using our own layout, we can do this as indicated in the tutorial, but is there any xml attribute that will display the TabIndicator at the top?

+6
source share
2 answers

This worked for me:

 LinearLayout tabs = ((LinearLayout) tabLayout.getChildAt(0)); for (int position = 0; position < tabs.getChildCount(); position++) { LinearLayout item = ((LinearLayout) tabs.getChildAt(position)); item.setRotationX(180); } 
0
source

Add this line to your TabLayout in XML

 app:tabIndicatorGravity="top" 
0
source

All Articles