I want to change indicator of tablayout from bottom to top.
my code
activity_tab.xml
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="#000000"
app:tabMode="scrollable"
/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
I want this result.
how to do
thx for ask me and sorry for bad english.
I have a different approach for doing that..
Set the tab indicator color same as the background color of the tab layout (So that you will not see the tab indicator at bottom)
Add a linear layout (horizontal) just above the tab layout containing views (same number as equal to number of tabs).
<LinearLayout android:layout_width="match_parent" android:layout_height="5dp" android:orientation="horizontal" android:background="@color/tab_bg" android:weightSum="3">
</LinearLayout>
Now just programmatically adjust the view backgrounds.
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
});
Use these selectors for customising the views
selector_tab_indicator_white.xml
selector_tab_indicator_blue.xml
The Result:
It can't be done by xml attribute, but can be done via setting image in background of tab with filled colour at top and transparent at bottom.
bg_tab.xml
cap.png
transparent at bottom
Don't use scale = -1 and things like that.
From XML you can use
app:tabIndicatorGravity="top"
From code you can use
setSelectedTabIndicatorGravity(INDICATOR_GRAVITY_TOP)