Im trying to use vector drawables on pre lollipop devices. I did all as instructed here but i still get this crash.
build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
}
}
apply plugin: 'com.android.application'
repositories {
maven { url 'http://maven.android-forever.com' }
jcenter()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.test.app"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
compile "de.greenrobot:eventbus:2.4.0"
compile 'de.greenrobot:greendao:2.1.0'
compile "com.af:android-utility:1.0.0.9"
compile project(':volleyplus')
compile project (':libvlc')
}
triangle.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/triangle_v"/>
</selector>
triangle_v.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="100dp"
android:width="100dp"
android:viewportHeight="100"
android:viewportWidth="100">
<path
android:name="triangle"
android:fillColor="#FF0000"
android:pathData="m 50,0 l 50,100 -100,0 z"/>
</vector>
layout.xml
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/triangle"/>
I also tried app:srcCompat
and in that case, drawable just dont show.
This code is going to work with vector if using
vectorDrawables.useSupportLibrary = true
And change android:src
to app:srcCompat
.
For example,
<ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/triangle"/>
to
<ImageView android:layout_width="match_parent" android:layout_height="match_parent" app:srcCompat="@drawable/triangle"/>