Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText drwableLeft don't work with vectors

Tags:

android

vector

In my app, I use vector drawables added in support library 23.2 for display vector icons and it works perfectly but when I set the vector to drawableLeft of EditText it does not work in pre-lollipop android versions. At runtime, ResourceNotFound exception occurs.

Caused by: android.content.res.Resources$NotFoundException: File 
res/drawable/layer_ic_user.xml from drawable resource ID #0x7f0200b3

This is my gradle configuration:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
    applicationId "com.example.test"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    vectorDrawables.useSupportLibrary = true
    generatedDensities = []
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),
       'proguard-rules.pro'
    }
}
sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/res/assets/'] } }
  }

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:design:23.3.0'
}
apply plugin: 'com.google.gms.google-services'

EditText :

     <EditText
        android:id="@+id/et_username_or_email"
        android:layout_width="@dimen/edit_text_width"
        android:layout_height="wrap_content"
        android:drawableLeft="@drawable/layer_list_ic_user"
        android:textColorHint="@color/ColorBlackPrimary"
        android:inputType="textEmailAddress|text"
        android:textColor="@color/ColorBlackPrimary"
        android:textSize="@dimen/text_small"
        />
like image 853
Edalat Feizi Avatar asked Apr 16 '16 06:04

Edalat Feizi


1 Answers

I face this problem and solve it by putting the vector image inside layer-list drawable like that: search_grey.xml

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_search_grey" /> 
</layer-list>

and in EditText:

        android:drawableLeft="@drawable/search_grey"
like image 173
Amal Kronz Avatar answered Oct 04 '22 15:10

Amal Kronz