android 圆角选中的tablayout

本文介绍如何使用Android的TabLayout组件并详细展示了如何自定义其样式,包括标签背景、选中状态背景及整体背景的设计。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里写图片描述

<android.support.design.widget.TabLayout
            android:id="@+id/table_layout"
            android:layout_width="150dp"
            android:layout_height="30dp"
            android:layout_gravity="center"
            android:background="@drawable/tablayout_background"
            android:textColor="@android:color/black"
            android:textSize="13sp"
            app:tabBackground="@drawable/tab_background"
            app:tabIndicatorHeight="0dp"
            app:tabSelectedTextColor="@color/white"
            app:tabTextColor="@color/main_color" />

app:tabBackground为标签背景
android:background为tablayout背景
tab_background(标签背景)

//设置选中背景为tablayout_select_background
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/tablayout_select_background" android:state_selected="true" />
</selector>

tablayout_select_background(选中标签背景)

//选中的背景
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="40dp" />
    <solid android:color="@color/main_color" />
</shape>

android:background(tablayout背景)

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="40dp" />
    <stroke
        android:width="1dp"
        android:color="@color/main_color" />
</shape>
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值