[英]Change color Progress indicator with Databinding?
I try all the ways but I can't change the color of progressbar.我尝试了所有方法,但无法更改进度条的颜色。 I tried to change it not only as binding but also in adapter but it doesn't work.
我试图不仅将其更改为绑定,而且还尝试将其更改为适配器,但它不起作用。 Can you please help?
你能帮忙吗?
..... .....
<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/progressBar"
android:layout_width="160dp"
android:layout_height="160dp"
android:progress="25"
app:indicatorColor="@{session.getChannel() == Channel.MOBILE ? @color/cerulean : @color/teal}"
app:indicatorDirectionCircular="counterclockwise"
app:indicatorInset="7dp"
app:indicatorSize="140dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:trackColor="#DEE3ED"
app:trackCornerRadius="5dp"
app:trackThickness="9dp" />
i get this error in this case Cannot find a setter for <com.google.android.material.progressindicator.CircularProgressIndicator app:indicatorColor> that accepts parameter type 'android.content.res.ColorStateList' If a binding adapter provides the setter, check that the adapter is annotated correctly and that the parameter type matches.在这种情况下我收到此错误无法找到接受参数类型“android.content.res.ColorStateList”的 <com.google.android.material.progressindicator.CircularProgressIndicator app:indicatorColor> 设置器如果绑定适配器提供设置器,请检查适配器被正确注释并且参数类型匹配。
val color = R.color.cerulean
progressBar.getIndeterminateDrawable().setColorFilter(color,
PorterDuff.Mode.SRC_IN)
And then I tried this code but again failed.然后我尝试了这段代码但又失败了。 undefined
不明确的
You can use custom binding adapter like this您可以像这样使用自定义绑定适配器
@BindingAdapter("app:indicatorColor")
fun setIndicatorColor(progress: CircularProgressIndicator, color: Int) {
progress.setIndicatorColor(color)
}
After that you can use your code in xml之后,您可以在 xml 中使用您的代码
app:indicatorColor="@{session.getChannel() == Channel.MOBILE ? @color/cerulean : @color/teal}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.