【问题标题】:Resources$NotFoundException Android 4.4资源$NotFoundException Android 4.4
【发布时间】:2017-11-18 13:56:58
【问题描述】:

原因:android.content.res.Resources$NotFoundException:文件 res/drawable/ic_ico_barcode.xml 来自 原因:android.view.InflateException: Binary XML file line #0: Error inflating class 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'
}

【问题讨论】:

    标签: android


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-11
      • 1970-01-01
      • 2017-03-21
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多