Android TabLayout指示符的绘制颜色不可见,同时无法添加自定义宽度。
创始人
2024-08-18 23:00:08
0

要解决Android TabLayout指示符的绘制颜色不可见,并且无法添加自定义宽度的问题,您可以使用自定义的TabLayout指示符来实现。

  1. 创建一个自定义的TabLayout指示符绘制类,继承自TabLayout.TabIndicatorInterpolator。例如,创建一个名为CustomTabLayoutIndicator的类。
public class CustomTabLayoutIndicator implements TabLayout.TabIndicatorInterpolator {
    private final Paint paint;
    private final int color;
    private final int width;

    public CustomTabLayoutIndicator(int color, int width) {
        this.color = color;
        this.width = width;
        this.paint = new Paint();
        this.paint.setColor(color);
        this.paint.setStrokeWidth(width);
        this.paint.setStyle(Paint.Style.FILL_AND_STROKE);
    }

    @Override
    public void draw(Canvas canvas, int startX, int stopX, int startY, int stopY, int selectedPosition, float selectionOffset) {
        float indicatorStartX = startX + width / 2;
        float indicatorStopX = stopX - width / 2;
        float indicatorY = startY + (stopY - startY) * (selectedPosition + selectionOffset);
        canvas.drawLine(indicatorStartX, indicatorY, indicatorStopX, indicatorY, paint);
    }
}
  1. 在您的Activity或Fragment中,找到TabLayout并设置自定义的TabLayout指示符绘制类。
TabLayout tabLayout = findViewById(R.id.tab_layout);
CustomTabLayoutIndicator customTabLayoutIndicator = new CustomTabLayoutIndicator(ContextCompat.getColor(this, R.color.indicator_color), getResources().getDimensionPixelSize(R.dimen.indicator_width));
tabLayout.setSelectedTabIndicator(customTabLayoutIndicator);

请确保将颜色资源和尺寸资源替换为您自己的颜色和宽度值。

通过使用自定义的TabLayout指示符绘制类,您可以在TabLayout中绘制自定义的指示符,并设置颜色和宽度,以满足您的需求。

相关内容

热门资讯

技巧辅助挂!hhpoker免费... 技巧辅助挂!hhpoker免费透视脚本,wepoker手机版透视脚本,手段教程(有挂详情)1、wep...
近年来!拱趴大菠萝十三水作弊,... 近年来!拱趴大菠萝十三水作弊,拱趴大菠萝万能挂图解,法门教程(存在有挂)1、拱趴大菠萝十三水作弊辅助...
黑科技技巧!we poker辅... 黑科技技巧!we poker辅助器v3.3,wepoker网页版透视方法,法子教程(有挂教学)在进入...
受玩家影响!wepoker开脚... 受玩家影响!wepoker开脚本视频,hhpoker辅助,妙计教程(揭秘有挂)1、很好的工具软件,可...
方法辅助挂!菠萝德州透视脚本,... 方法辅助挂!菠萝德州透视脚本,hhpoker是真的还是假的,窍要教程(有挂技巧)一、hhpoker是...
做出回应!wepoker辅助器... 做出回应!wepoker辅助器官方,wepoker脚本下载,模块教程(揭秘有挂)wepoker辅助器...
日前!菠萝辅助器免费版的特点,... 日前!菠萝辅助器免费版的特点,红龙poker辅助器免费观看,练习教程(有挂透视)1、全新机制【菠萝辅...
黑科技技巧!wepokerpl... 黑科技技巧!wepokerplus外挂,wepoker辅助软件视频,步骤教程(有挂规律)1、这是跨平...
在玩家背景下!wepoker一... 在玩家背景下!wepoker一直输的号能继续打吗,wepoker祈福有用吗,资料教程(发现有挂)在玩...
黑科技教程!wepoker有辅... 黑科技教程!wepoker有辅助吗,wepokerh5破解,项目教程(有挂规律)亲,关键说明,wep...