Logcat警告:请考虑使用Resources.getDrawable(int,Theme)或Context.geDra



当我想输入数据,但在代码中没有使用任何可绘图项时,我发现了这个错误。我只是使用一个简单的EditText来读取数据。我在这个论坛上提到了许多其他解决方案,但这并不是为了帮助。

Drawable android:drawable/text_cursor_material has unresolved theme attributes! Consider using Resources.getDrawable(int, Theme) or Context.getDrawable(int).
java.lang.RuntimeException
    at android.content.res.Resources.getDrawable(Resources.java:740)
    at android.support.v7.widget.TintResources.superGetDrawable(TintResources.java:48)
    at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:374)
    at android.support.v7.widget.TintResources.getDrawable(TintResources.java:44)
    at android.widget.Editor$InsertionHandleView.getHotspotX(Editor.java:3772)
    at android.widget.Editor$HandleView.updateDrawable(Editor.java:3399)

编辑(build.gradle)

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.example.user.myapp"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    // Enabling multidex support.
   // multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
wearApp project(':wear')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:design:23.2.0'
compile files('libs/org.apache.http.legacy.jar')
compile 'com.android.support:support-v4:23.2.0'
}

总结此问题

  • 使用ContextCompat.getDrawable(Context, int)而不是getResources().getDrawable(int)(已弃用)。

  • 如果可用,请使用0.8.5.7或更高版本,但不使用材质对话框0.8.5.6

最新更新