0

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!

David Wasser
  • 93,459
  • 16
  • 209
  • 274
Preem Palver2
  • 180
  • 1
  • 11
  • 1
    Removed tag `android-studio` as that tag is for questions/issues with the Android Studio product. Your question has nothing to do with Android Studio – David Wasser Sep 01 '23 at 17:12
  • What do you mean by "my widget won't load"? Please explain in more detail exactly what the problem is. Do you get exceptions, errors? What is the expected behaviour? – David Wasser Sep 01 '23 at 17:13
  • by "my widget won't load" I mean that when updating my widget and going to the home screen, I see a white box with the text "Widget could not be loaded" meaning there's an issue with my code. – Preem Palver2 Sep 02 '23 at 05:19
  • If you remove the calls to `views.setInt()` does your widget show? Did you check the logcat for errors? – David Wasser Sep 02 '23 at 09:35

1 Answers1

1

You need to call setProgressBackgroundTintList() and setProgressTintList() on your remote Views. Both these methods take a ColorStateList as a parameter. So you need to call views.setColorStateList() to do this. See https://developer.android.com/reference/android/widget/RemoteViews?hl=en#setColorStateList(int,%20java.lang.String,%20android.content.res.ColorStateList)

David Wasser
  • 93,459
  • 16
  • 209
  • 274