资源$ NotFoundException Android 4.4

时间:2017-11-18 13:56:59

标签: android

引起:android.content.res.Resources $ NotFoundException:文件res / drawable / ic_ico_barcode.xml来自 引起:android.view.InflateException:二进制XML文件行#0:错误膨胀类Button

无法找到@ drawable / ic_ico_barcode,因为下面按钮中的drawableLeft,但它适用于Android 7.1

Drawables仅在“drawable”文件夹中。 UseSupportLibrary设置为true,gradle版本是新的。我该如何解决?

<Button
            android:id="@+id/button6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/button7"
            android:layout_alignLeft="@+id/button7"
            android:layout_alignStart="@+id/button7"
            android:layout_marginBottom="11dp"
            android:width="210dp"
            android:background="@color/GSWhite"
            android:drawableLeft="@drawable/ic_ico_barcode"
            android:onClick="onScanClick"
            android:paddingLeft="20dp"
            android:paddingRight="25dp"
            android:text="SKENOVAT"
            android:textColor="@color/GSGreen"
            android:textSize="19dp" />

Gradle版本4.1

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.greenscan.app.greenscan"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:25.0.0'
    compile 'com.android.support:support-vector-drawable:25.0.0'
    compile 'me.dm7.barcodescanner:zbar:1.9.8'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'io.reactivex.rxjava2:rxjava:2.1.3'
    compile 'com.jakewharton.rxbinding2:rxbinding:2.0.0'
    compile 'com.jakewharton.rxbinding2:rxbinding-appcompat-v7:2.0.0'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'commons-codec:commons-codec:1.10'
    compile('com.afollestad:bridge:5.1.2') {
        exclude group: 'org.json', module: 'json'
    }
    compile 'com.android.support:multidex:1.0.0'
    testCompile 'junit:junit:4.12'
}

1 个答案:

答案 0 :(得分:0)

drawableLeft和drawableRight即使对于Android 5.0以下版本的支持库也不起作用。

  

来自Google:从Android支持库23.3.0开始,支持向量drawable只能通过app:srcCompat或setImageResource()加载..
  http://android-developers.blogspot.ru/2016/02/android-support-library-232.html

在我的情况下,我创建了一个包含FrameLayout的复合视图,而FrameLayout包含了Button和AppCompactImageView。 Compound View example

或者您可以使用单个xxxhdpi图像而不是矢量drawable。