Alexander
Alexander

Reputation: 21

Android Widget use app:srcCompat for ImageView

I have Widget with ImageView. When i use android:src for set image for ImageView everything all right, but when i use app:srcCompat image don't show. Is there a way to use app:srcCompat in Android Widget?

It's set in my project:

xmlns:app="http://schemas.android.com/apk/res-auto"

android {  
 defaultConfig {  
    vectorDrawables.useSupportLibrary = true  
    }
}


  minSdkVersion 24
  targetSdkVersion 29

Upvotes: 1

Views: 814

Answers (2)

Steven Meliopoulos
Steven Meliopoulos

Reputation: 4768

I don't think this is possible. ImageView doesn't actually have a app:srcCompat attribute (see here). The reason why you're normally able to use it, is that ImageView is automatically replaced by AppCompatImageView when you use the appcompat library. However this doesn't work with widgets since they are based on RemoteViews. As you have seen, with RemoteViews you can only use ImageView and not AppCompatImageView. Even if you add the appcompat library to your own app, the problem is that the RemoteViews object for your widget will be handed to the process of the app that will display the widget (typically the launcher), where we can't assume appcompat to be available.

Are you trying to use appcompat because of problems with your vector assets? If you describe the problem you're having with them maybe we can find a way to make it work with regular ImageViews.

Upvotes: 3

Justinas Krutulis
Justinas Krutulis

Reputation: 39

Try <androidx.appcompat.widget.AppCompatImageView> instead if <ImageView>

Upvotes: -1

Related Questions