I have this progressbar view:
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="6dp"
android:layout_centerVertical="true"
android:max="100"
android:progress="20"
android:progressDrawable="@drawable/progress_bar_shape"
android:progressTint="#03ff46" // this is the value I'm trying to set via RemoteView
android:progressBackgroundTint="#a8a8a8" // also this one
/>
I'm trying to set the background color & fill color with RemoteView (I'm using it for a widget)
views.setInt(R.id.progressBar, "setProgressTintList", clockData.getDarkColor());
My widget can't load, so this must be the wrong way to do this.
How can I fix this problem?
Thank you!
You need to call
setProgressBackgroundTintList()andsetProgressTintList()on your remoteViews. Both these methods take aColorStateListas a parameter. So you need to callviews.setColorStateList()to do this. See https://developer.android.com/reference/android/widget/RemoteViews?hl=en#setColorStateList(int,%20java.lang.String,%20android.content.res.ColorStateList)ColorStateListis used to set a list of colors depending on the state of a UI element (pressed, enabled, selected, etc.). If you only want to set the color, regardless of its state, you can simply create aColorStateListthat contains a single color. Here's an example of creating aColorStateListcontaining just a single color programatically and using that to set the color inRemoteViews: