您好,登錄后才能下訂單哦!
在TabLayout中,Button通常不作為標(biāo)簽頁標(biāo)簽的一部分,而是作為標(biāo)簽頁內(nèi)容的一部分??梢詫utton放置在ViewPager或者Fragment中,作為TabLayout的一個(gè)標(biāo)簽頁內(nèi)容。這樣用戶點(diǎn)擊對(duì)應(yīng)的Tab標(biāo)簽時(shí),就會(huì)顯示Button所在的頁面內(nèi)容。具體的布局可以參考以下示例:
<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=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
在ViewPager中設(shè)置多個(gè)Fragment作為不同的標(biāo)簽頁內(nèi)容,每個(gè)Fragment中可以放置一個(gè)Button或其他需要顯示的內(nèi)容。通過TabLayout和ViewPager的聯(lián)動(dòng),用戶可以方便地切換不同的標(biāo)簽頁內(nèi)容。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。