未能在当前主题中找到样式"cardView样式" [英] failed to find style 'cardView Style' in current theme

查看:68
本文介绍了未能在当前主题中找到样式"cardView样式"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新支持库版本后,27.1.0 Android Studio 无法呈现CardView.它显示错误消息为

After updating support library version 27.1.0 Android Studio unable to render CardView. It shows error message as

failed to find style 'cardView Style' in current theme

但是编译没有错误,在手机上查看时也没有区别.

But no error in compiling and no difference while seeing on the phone.

我已将支持库版本恢复为27.0.2,并且可以正常显示.

I have reverted the support library version to 27.0.2 and it's rendering fine.

支持库或 Android Studio 存在问题吗?该如何解决?

The issue with support library or Android studio? How to fix this?

App Level Gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'realm-android'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.tmmmt.tmmmt"
        minSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            buildConfigField 'String', 'FS_CLIENT_ID', FOURSQUARE_CLIENT_ID
            buildConfigField 'String', 'FS_CLIENT_SECRET', FOURSQUARE_CLIENT_SECRET
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            buildConfigField 'String', 'FS_CLIENT_ID', FOURSQUARE_CLIENT_ID
            buildConfigField 'String', 'FS_CLIENT_SECRET', FOURSQUARE_CLIENT_SECRET
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    flavorDimensions "default"

    productFlavors {
        dev {
            dimension "default"
            versionNameSuffix "-dev"
            buildConfigField 'String', 'BASE_URL', BASE_URL_DEV
            manifestPlaceholders = [GEO_API_KEY: GOOGLE_MAP_KEY_DEV]
        }

        beta {
            dimension "default"
            versionNameSuffix "-beta"
            buildConfigField 'String', 'BASE_URL', BASE_URL_BETA
            manifestPlaceholders = [GEO_API_KEY: GOOGLE_MAP_KEY_BETA]
        }

        live {
            dimension "default"
            buildConfigField 'String', 'BASE_URL', BASE_URL_LIVE

            manifestPlaceholders = [GEO_API_KEY: GOOGLE_MAP_KEY_LIVE]
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation "org.jetbrains.anko:anko-common:$anko_version"
    implementation "com.android.support:appcompat-v7:$support_version"
    implementation "com.android.support:support-v13:$support_version"
    implementation "com.android.support:design:$support_version"
    implementation "com.android.support:cardview-v7:$support_version"
    implementation "com.google.firebase:firebase-messaging:$play_version"
    implementation "com.google.android.gms:play-services-maps:$play_version"
    implementation "com.google.android.gms:play-services-location:$play_version"
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.8.0'
    implementation 'com.squareup.okhttp3:okhttp:3.8.1'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation 'com.wang.avi:library:2.1.3'
    implementation 'com.tmmmt.library:arrowtab:1.3'
    implementation 'com.github.stfalcon:chatkit:0.2.2'
    implementation 'com.amazonaws:aws-android-sdk-core:2.6.16'
    implementation 'com.amazonaws:aws-android-sdk-cognito:2.6.16'
    implementation 'com.amazonaws:aws-android-sdk-s3:2.6.16'
    implementation 'com.orhanobut:logger:2.1.1'
    implementation 'com.tmmmt.library:animations:0.6'
    implementation 'com.github.bumptech.glide:glide:4.6.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
    compile('io.socket:socket.io-client:1.0.0') {
        exclude group: 'org.json', module: 'json'
    }
    /*Fort*/
    implementation project(':FortSDKv1.4.1')
    implementation 'com.victor:lib:1.0.1'
    implementation 'com.shamanland:fonticon:0.1.8'
    implementation('com.nispok:snackbar:2.11.0') {
        exclude group: 'com.google.android', module: 'support-v4'
    }
    implementation 'com.google.guava:guava:23.0-android'
    implementation 'org.bouncycastle:bcprov-jdk16:1.46'
    implementation 'commons-codec:commons-codec:1.10'
    /*Fort*/
}

apply plugin: 'com.google.gms.google-services'

项目级别分级:

buildscript {
    ext.kotlin_version = '1.2.30'
    ext.anko_version = '0.10.1'
    ext.support_version = '27.1.0'
    ext.play_version = '11.8.0'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "io.realm:realm-gradle-plugin:4.3.2"
        classpath 'com.google.gms:google-services:3.1.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://mymavenrepo.com/repo/eDGOo6Dqr4f6uNA0HoWX/"
            credentials {
                username = 'myMavenRepo'
                password = 'tmmmt123'
            }
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

更新:

Android Studio 3.2中没有这样的错误.错误完全消失了.

There is no such error from Android Studio 3.2. The error was gone completely.

推荐答案

检查CardView的来源可以看到构造函数

Checking the source of CardView one can see that the constructor

public CardView(@NonNull Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    initialize(context, attrs, 0);
}

已更改为

public CardView(@NonNull Context context, @Nullable AttributeSet attrs) {
    this(context, attrs, R.attr.cardViewStyle);
}

新属性cardViewStyle在库中定义.我猜出于某种原因,Android Studio预览版不包含该库中该属性的值.我不确定它是否通常解析库中定义的自定义属性,这是一个错误,还是故意的.

And the new attribute cardViewStyle is defined in the library. I guess that the Android Studio preview is not including the value for this attribute from the library, for some reason. I'm not sure if it usually resolves custom attributes defined in libraries and this is a bug, or if this is intended.

解决方法1

解决主题中的属性(可能仅在调试版本中),这样就可以消除错误. @style/CardView已在支持库中定义,因此您无需创建样式,只需引用它即可.

Resolve the attribute in your theme (maybe only in debug version), this way the error is gone. @style/CardView is already defined in the support library so you don't need to create the style, just reference it.

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="cardViewStyle">@style/CardView</item>
</style>

确保在布局预览中使用AppTheme并清理构建.

Be sure to use AppTheme in the layout preview and clean build.

解决方法2

使用tools命名空间添加样式,以免影响您的生产代码.呈现错误将被记录,但是您仍然会看到CardView

Add the style with tools namespace so that it won't affect your production code. The rendering error will be logged, but you will see the CardView anyway

<android.support.v7.widget.CardView
    tools:style="@style/CardView"
    ...

好消息

Android Studio 3.1似乎可以正确处理此问题,不需要任何解决方法(尽管布局预览中的错误仍会记录).

Android Studio 3.1 seems to be handling this correctly, no workaround needed (the error in the layout preview is still logged though).

在Android Studio 3.2(当前在Canary频道)上,错误消失了.

On Android Studio 3.2 (currently in Canary channel) the error is gone.

这篇关于未能在当前主题中找到样式"cardView样式"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆