您的位置:宽带测速网 > 编程知识 > progressbar颜色如何设置

progressbar颜色如何设置

2025-06-17 15:03来源:互联网 [ ]

要设置progressbar的颜色,可以使用ProgressBar的setProgressTintList方法来设置进度条的颜色。具体步骤如下:

    创建一个颜色资源文件,例如colors.xml,定义需要的颜色,例如:
<resources><color name="progress_color">#FF4081</color></resources>
    在代码中获取颜色资源,并设置给ProgressBar:
ProgressBar progressBar = findViewById(R.id.progressBar);progressBar.setProgressTintList(ColorStateList.valueOf(getResources().getColor(R.color.progress_color)));

这样就可以设置进度条的颜色为定义的颜色。