So I want to programatically make the tab indicator color active. I have a sort of progress bar at the top, and I want each tab that has been selected previously to stay colored (or selected).
Here is my XML, although I doubt it helps.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FinishProfile">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@android:color/white"
app:tabIndicatorColor="@android:color/holo_blue_light"
app:tabIndicatorHeight="5dp"
app:tabRippleColor="@android:color/white"
app:tabTextColor="@android:color/white">
</com.google.android.material.tabs.TabLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
And here is what I want to do, essentially.
val tab1 = tabs.getTabAt(0)
// I need something like: tab1.tabIndicatorActive = true
I think it will work
tabs!!.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener{
override fun onTabSelected(tab: TabLayout.Tab?) {
viewPager!!.currentItem = tab?.position!!
if (tab.position == 0) {
//like this: tabs.setSelectedTabIndicatorColor(Color.BLUE)
//or like this: tabs.getTabAt(0)!!.getIcon()!!.setAlpha(100)
}else if (tab.position == 1) {
}
}
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.