带圆角的自定义TabLayout

时间:2017-10-07 17:34:36

标签: android

我想创建一个像这样的tablayout:

enter image description here

正如您所看到的,我为标签布局背景设置了圆角。我尝试了以下代码:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|enterAlways"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

<android.support.design.widget.TabLayout
    android:id="@+id/tabs2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabIndicatorColor="#CECECF"
    app:tabBackground="@drawable/tab_bar_bg"
    app:tabMode="fixed"
    app:tabGravity="fill"/>

结果:

enter image description here

有没有办法用tablayout来实现这个圆角?如果答案是肯定的那么我的路线图是什么?

Ps:不要介意屏幕截图上的图标或图标颜色。

2 个答案:

答案 0 :(得分:3)

将此文件添加到drawable目录,并将其添加到自定义选项卡布局中作为背景。

shape.xml

aria2c

答案 1 :(得分:0)

设置TabLayout>像这样的背景

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/tab_background"/>
    <stroke android:color="@color/tab_border" android:width="1px"/>
    <corners android:radius="@dimen/tab_corner_radius"/>
</shape>
相关问题