setTextColor 是 Android 中用于设置文本颜色的方法,它主要应用于 TextView 及其子类(如 Button、EditText 等)控件。对于其他类型的控件,如 ImageView、ProgressBar 等,setTextColor 方法是不适用的。
如果你需要为其他类型的控件设置颜色,你需要使用相应的方法。例如:
-
对于
ImageView,你可以使用setColorFilter方法设置颜色遮罩:ImageView imageView = findViewById(R.id.imageView); imageView.setColorFilter(ContextCompat.getColor(context, R.color.your_color)); -
对于
ProgressBar,你可以使用setProgressTintList和setIndeterminateTintList方法设置进度条的颜色:ProgressBar progressBar = findViewById(R.id.progressBar); ColorStateList progressTintList = ContextCompat.getColorStateList(context, R.color.your_progress_color); progressBar.setProgressTintList(progressTintList); ColorStateList indeterminateTintList = ContextCompat.getColorStateList(context, R.color.your_indeterminate_color); progressBar.setIndeterminateTintList(indeterminateTintList);

便宜VPS测评









