簡體   English   中英

Android Studio:標簽指示器處於活動狀態

[英]Android Studio: Tab indicator active

所以我想以編程方式使選項卡指示器顏色處於活動狀態。 我在頂部有一個進度條,我希望以前選擇的每個選項卡保持彩色(或選中)。

這是我的 XML,雖然我懷疑它有幫助。

<?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>

這就是我想要做的,本質上。

val tab1 = tabs.getTabAt(0)
// I need something like: tab1.tabIndicatorActive = true

我認為它會起作用

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) {

         }
     }

})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM