棒棒糖中的进度条颜色不一致

问题描述 投票:0回答:1

我使用以下代码创建进度条。我尝试更改其颜色,它适用于Android 6.0+,但是在我的Android 5.1模拟器上运行它时却不起作用。 image

我该如何解决这个问题?

这是我的代码。

    <ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progressb"
    android:progressTint="@color/colorAccent"
    android:progressTintMode="multiply"
    />
android progress-bar android-progressbar
1个回答
0
投票

我认为是为了支持向后的Android OS手机,我以编程方式做到了。我曾经添加以下代码来处理

int colorAccent = ContextCompat.getColor(context, R.color.colorAccent);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    DrawableCompat.setTint(drawable, colorAccent);
} else {
    drawable.mutate().setColorFilter(colorAccent, PorterDuff.Mode.SRC_IN);
}
© www.soinside.com 2019 - 2024. All rights reserved.