Reputation: 103
I try to use AppCompatImageView to display a vector image in a widget, but image is not displayed (instead I got a cut message "Error loading..."). The same piece of code works well in my main activity (both are in LinearLayout). Is there a limitation for widgets ? What do I miss ?
My minSdkVersion is 19, and I use androidx.
I tried to change layout to a standard LinearLayout.
My XML :
<androidx.appcompat.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/widget_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/appwidget_image"
android:layout_width="match_parent"
android:layout_height="50dp"
android:contentDescription="@+id/appwidget_label"
android:padding="5dp"
app:srcCompat="@drawable/ic_baseline_toggle_off_24px"
android:tint="@color/colorAccent"/>
<TextView
android:id="@+id/appwidget_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_horizontal"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:singleLine="true"
android:text="@string/appwidget_default_text"
android:textAlignment="gravity"
android:textColor="@color/colorAccent"
android:textSize="12sp" />
</androidx.appcompat.widget.LinearLayoutCompat>
Extract of my build.gradle :
android {
compileSdkVersion 28
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0-alpha05'
implementation 'androidx.appcompat:appcompat-resources:1.1.0-alpha05'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
implementation 'com.loopj.android:android-async-http:1.4.9'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'de.greenrobot:eventbus:2.4.0'
implementation 'com.j256.ormlite:ormlite-android:4.48'
implementation 'androidx.work:work-runtime:2.0.1'
}
Some messages in logcat I don't understand (but not necessary related to my problem) :
05-21 19:38:09.886 12404-12404/com.yadoms.widgets.statedisplay E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method androidx.appcompat.widget.AppCompatImageHelper.hasOverlappingRendering
05-21 19:38:09.886 12404-12404/com.yadoms.widgets.statedisplay W/dalvikvm: VFY: unable to resolve instanceof 216 (Landroid/graphics/drawable/RippleDrawable;) in Landroidx/appcompat/widget/AppCompatImageHelper;
05-21 19:38:09.906 12404-12404/com.yadoms.widgets.statedisplay E/dalvikvm: Could not find class 'android.view.textclassifier.TextClassificationManager', referenced from method androidx.appcompat.widget.AppCompatTextClassifierHelper.getTextClassifier
05-21 19:38:10.066 12404-12404/com.yadoms.widgets.statedisplay E/EGL_emulation: tid 12404: eglSurfaceAttrib(1199): error 0x3009 (EGL_BAD_MATCH)
Thanks for your help
Upvotes: 3
Views: 4441
Reputation: 1006644
Is there a limitation for widgets ?
Yes. You are limited to the roster of widgets listed in the documentation.
In particular, you cannot use any custom widgets, either your own or from libraries (e.g., AndroidX). That is because your app is not rendering the app widget — the home screen is.
Upvotes: 4