Android 设置“材质”选项卡布局的样式
我正在使用kotlin在我的android应用程序中进行材料设计。我想知道我如何设计我的标签布局,就像下图所示。谢谢Android 设置“材质”选项卡布局的样式,android,kotlin,material-design,android-tablayout,material-components,Android,Kotlin,Material Design,Android Tablayout,Material Components,我正在使用kotlin在我的android应用程序中进行材料设计。我想知道我如何设计我的标签布局,就像下图所示。谢谢 已解决: <com.google.android.material.tabs.TabLayout android:id="@+id/profileFreelancerTabLayoutCu" android:layout_width="match_parent" android:layout_height="wrap_c
已解决:
<com.google.android.material.tabs.TabLayout
android:id="@+id/profileFreelancerTabLayoutCu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabTextColor="@color/colorPrimary"
android:layout_marginVertical="20dp"
android:layout_marginHorizontal="60dp"
app:tabIndicatorGravity="stretch"
app:tabIndicator="@drawable/tab_indicator_shape"
android:background="@drawable/thicker_stroke_tab_layout"
app:tabSelectedTextColor="@color/colorWhite"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginBottom="10dp"
app:layout_constraintTop_toBottomOf="@+id/registeredOnValueProfileFreelancerCu"
/>
只需使用
app:tabIndicatorGravity=“stretch”
属性来拉伸指示器,以匹配此布局中选项卡项的高度和宽度。您还可以使用
app:tabIndicatorColor
属性设置背景色:
<com.google.android.material.tabs.TabLayout
app:tabIndicatorGravity="stretch"
app:tabIndicatorColor="@color/...."
...>
删除
style=“@style/Widget.AppCompat.Light.ActionBar.TabBar”
发布您的layout@GabrieleMariotti编辑了我的问题好的,谢谢这项工作,但是我怎样才能得到大纲和CornerDuis?@Aldor当前(1.2.0-alpha06
)“材质”组件中的TabLayout
不支持本机造型。您可以创建一个带有形状(用xml定义)的选择器,并使用选项卡background
属性应用它,或者您可以将表格布局
以圆角方式包装在父视图中(CardView
,LinearLayout
)。是的,我已经用解决方案编辑了这个问题,非常感谢!
<com.google.android.material.tabs.TabLayout
app:tabIndicatorGravity="stretch"
app:tabIndicatorColor="@color/...."
...>