java - 无法解析符号 Theme.MaterialComponents.Light.NoActionBar (Android Studio)

标签 java android androidx material-components-android material-components

我在 styles.xml 中遇到 'Theme.MaterialComponents.Light.NoActionBar' 错误('Theme.MaterialComponents.Light.NoActionBar) ' 由于错误而变成红色)在几次 gradle 更新后。我的组件也没有按照我的设计理念很好地排列。

我已经清理并重建项目,使缓存/重新启动无效,更新 gradle(可能不是正确的答案),但没有答案。我只是想也许我是唯一一个遇到这个问题的人,也许是我的初学者水平问题:')

样式.xml

`

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/hitam</item>
    <item name="colorAccent">@color/colorAccent</item>

</style>

`

项目等级

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

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

'

应用程序分级

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

      android {
          compileSdkVersion 29
          defaultConfig {
          applicationId "blablabla"
          minSdkVersion 23
          targetSdkVersion 29
          versionCode 1
          versionName "1.0"
          testInstrumentationRunner               "androidx.test.runner.AndroidJUnitRunner"

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion '29.0.1'
}

compileOptions {

    sourceCompatibility JavaVersion.VERSION_1_6
    targetCompatibility JavaVersion.VERSION_1_6

    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7

    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8

}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.10.0'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation 'com.google.firebase:firebase-auth:18.1.0'
    implementation 'com.google.firebase:firebase-database:18.0.0'
    implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
}

apply plugin: 'com.google.gms.google-services'
buildToolsVersion = '29.0.1'

          }

`

我希望本地球上没有人出现此错误时,该错误是不可见的。请帮忙T_T

最佳答案

Material Components themes包含在Material Components for Android library中.

由于您使用的是 androidx 库,只需在 app/build.gradle 文件中添加此依赖项即可。

dependencies {
    // ...
    implementation 'com.google.android.material:material:x.x.x'
    // ...
  }

目前(2022年4月29日)最新稳定版本为

implementation 'com.google.android.material:material:1.5.0'

在这里您可以找到所有信息the setup .

关于java - 无法解析符号 Theme.MaterialComponents.Light.NoActionBar (Android Studio),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57282947/

相关文章:

java - 如何将回历日期转换为公历日期,反之亦然

没有 fragment 的 Android 功能区菜单

android - 如何从 Android 导航 Controller 中的通知导航 Fragment

java - 独立于平台的方式获取当前java可执行路径和文件名

java - 类型参数的遮蔽

java - 编译java的小麻烦

java - 在 LDAP 查询中是否可以加入?

Android GoogleMaps - 从基本 fragment Activity 抽象类继承 map fragment

java - ViewModelProvider.Factory 在 Android 上使用 Dagger 和 Java 在 fragment 上保持为 null

java - Android Studio : cannot access MenuHost class file for androidx. core.view.MenuHost 未找到