我在TabLayout
中添加了2个选项卡,以下是我的代码。
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
style="@style/AppTabLayout"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_gravity="center"
app:tabBackground="@drawable/tab_selector_statistics"
android:background="@drawable/tab_statistics"
app:tabContentStart="24dp"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/white"
app:tabTextColor="@color/black"
app:layout_constraintBottom_toBottomOf="@+id/view5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/view5"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true" />
我得到了以下输出。
但是我想要选项卡占据整个屏幕的宽度,如下所示。 以下是我在styles.xml
文件中定义的AppTabLayout
样式。<style name="AppTabLayout" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">@null</item>
<item name="tabIndicatorHeight">1dp</item>
<item name="tabPaddingStart">16dp</item>
<item name="tabPaddingEnd">16dp</item>
<item name="tabSelectedTextColor">@color/white</item>
</style>
android:layout_width="0dp"
吗?在ConstraintLayout
中不支持match_parent
。 - Eugen Pechanec0dp
,但仍然得到相同的输出。 - dev90