TabLayout 去除下方指示线

TabLayout.setSelectedTabIndicatorHeight(0); //已过时
TabLayout.setSelectedTabIndicator(null);//使用这个方法
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将 Android TabLayout指示器颜色设置为渐变色,可以执行以下步骤: 1. 定义渐变色 在 drawable 目录下创建一个 gradient.xml 文件,定义渐变色。例如: ``` <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="@color/colorStart" android:endColor="@color/colorEnd" android:angle="0" /> </shape> ``` 其中,@color/colorStart 和 @color/colorEnd 分别指定渐变色的起始和结束颜色,android:angle 表示渐变的角度。 2. 设置 TabLayout指示器颜色 通过 TabLayout.setSelectedTabIndicatorColor() 方法设置 TabLayout指示器颜色。这里将渐变色作为指示器的颜色: ``` TabLayout tabLayout = findViewById(R.id.tabLayout); tabLayout.setSelectedTabIndicatorColor(ContextCompat.getColor(this, R.color.transparent)); GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.setColor(ContextCompat.getColor(this, R.color.transparent)); gradientDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT); gradientDrawable.setOrientation(GradientDrawable.Orientation.LEFT_RIGHT); gradientDrawable.setColors(new int[]{ ContextCompat.getColor(this, R.color.colorStart), ContextCompat.getColor(this, R.color.colorEnd) }); tabLayout.setSelectedTabIndicator(gradientDrawable); ``` 其中,tabLayout.setSelectedTabIndicatorColor() 方法设置指示器的颜色为透明,防止出现默认的颜色叠加在渐变色上的情况。然后创建一个 GradientDrawable 对象,设置渐变色的起始和结束颜色,以及渐变的方向。最后调用 tabLayout.setSelectedTabIndicator() 方法将渐变色作为指示器的背景。 3. 设置 TabLayout指示器高度 通过 TabLayout.setSelectedTabIndicatorHeight() 方法设置 TabLayout指示器高度。例如: ``` tabLayout.setSelectedTabIndicatorHeight(getResources().getDimensionPixelSize(R.dimen.indicator_height)); ``` 其中,R.dimen.indicator_height 是在 dimens.xml 文件中定义的指示器高度的值。 这样,就可以将 Android TabLayout指示器颜色设置为渐变色,并且可以设置指示器的高度。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值