Android 无法解析 Material 组件

标签 android xml android-appcompat android-design-library android-textinputlayout

我收到这个错误:

Cannot resolve symbol '@style/Widget.MaterialComponents.TextInputLayout.OutlineBox'

将此行添加到我的 XML 中的 TextInputLayout 后出现此错误:

style="@style/Widget.MaterialComponents.TextInputLayout.OutlineBox" 

这是我的完整 XML 代码(删除了不相关的约束/边距):

<android.support.design.widget.TextInputLayout
    android:id="@+id/textInputLayout2"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlineBox"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:counterEnabled="true"
    app:counterMaxLength="300">

    <android.support.design.widget.TextInputEditText
        android:id="@+id/cheese_description"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="start"
        android:hint="@string/cheese_description" />

</android.support.design.widget.TextInputLayout>

这是我的应用build.gradle:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "app.cheese.cheese.some.sample_cheese"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion '27.0.3'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.firebase:firebase-auth:11.8.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.android.support:design:27.0.2'
    compile 'com.google.firebase:firebase-core:11.8.0'
    implementation 'com.android.support:appcompat-v7:27.0.2'
    compile 'com.android.support:support-v4:27.0.2'
    compile 'com.google.firebase:firebase-storage:11.8.0'
    compile 'com.google.firebase:firebase-messaging:11.8.0'
    compile 'com.firebaseui:firebase-ui-auth:3.1.3'
    compile 'com.google.firebase:firebase-database:11.8.0'
    implementation 'com.android.support:cardview-v7:27.0.2'
    implementation 'com.android.support:recyclerview-v7:27.0.2'
    implementation 'com.firebaseui:firebase-ui-database:3.2.1'
}

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

这是我的另一个build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.1.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

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

我试过:

  • 将 buildToolsVersions 从“27.0.3”更改为“27.0.2”并同步
  • 使缓存无效/重新启动
  • 重建项目

我采用了导致错误的 XML 代码行 from the material.io components here .有谁知道我做错了什么?

谢谢你:)

最佳答案

Material Components尚未在 com.android.support:design 依赖项下发布新版本(或通过您可以包含在 build.gradle 文件中的任何其他官方依赖项)所以您在 27.0.2 中看到的内容不包含任何最近的更改 - 例如对 Widget.MaterialComponents.TextInputLayout.OutlineBox 的支持。

如果您想访问最新的更改,您必须将所需的 Material Components 库部分直接复制到您的项目中。

关于Android 无法解析 Material 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48603515/

相关文章:

android - 将多个文件添加到androidManfist.xml

android - 我如何像 Google Map 一样实现 Feature Like “Precache Map Area”

android - 如何在谷歌地图 Android 上按名称搜索地址

java - 每秒更新通知中的 RemoteViews

java - 目标是从我的项目中删除文件不起作用

regex - 匹配 XML 数据中的特定 CDATA 部分

android - 为什么添加导航组件会导致Gradle错误 “error: resource android:attr/dialogCornerRadius not found.”

android - Appcompat/添加一个库与android studio

android - play-services-oss-licenses 的主题

android - 如何不断地将GPS数据从android发送到服务器直到应用程序关闭