J'utilise le vecteur dans ImageView dans mon activité, l'application fonctionne très bien sur Android 7.0 mais se bloque sur Android 4.4. Logcat dit, Resources$NotFoundException
. J'ai essayé des solutions postées ici sur stackoverflow mais aucune d'entre elles ne semble fonctionner.
Voici les solutions que j'ai essayées.
ajouté dans mon fichier gradle
defaultConfig { vectorDrawables.useSupportLibrary = true }
a ajouté dans OnCreate d'activité
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
- Remplacée
android:src
avecapp:srcCompat
dans un fichier XML.
Ceci est mon code XML
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_arrow_back_white_24dp"
android:tint="@color/colorPrimary"
android:id="@+id/details_back"
android:layout_margin="15dp"
android:layout_alignParentStart="true"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/share"
android:tint="@color/colorPrimary"
android:id="@+id/details_share"
android:layout_margin="15dp"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
c'est le code dans le fichier JAVA
ImageView detail_share;
detail_share = (ImageView) findViewById(R.id.details_share);
detail_share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// code for sharing item
}
});
En outre, l'erreur se produit dans la deuxième ImageView, pas le premier, en dépit d'être exactement le même. Je traite les deux images exactement la même chose dans le fichier java aussi.