简体   繁体   中英

Cannot resolve symbol Theme.MaterialComponents.Light.NoActionBar (Android Studio)

I've got an error for 'Theme.MaterialComponents.Light.NoActionBar' in styles.xml (the 'Theme.MaterialComponents.Light.NoActionBar' is colored red because of error) after several gradle update. My component are also not well arranged according to my idea of designing.

I've already clean and rebuild project, invalidate caches/restart, update the gradle (maybe not the correct answer) and there's no answer for this. I just think maybe I'm the only one that have this problem maybe for my beginner level problem :')

styles.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>

`

Project gradle

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
}

'

App gradle

      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'

          }

`

I expect the error is not visible when there's like no one in this earth that have this error. PLEASE HELP T_T

The Material Components themes are included in the Material Components for Android library .

Since you are using androidx library just add this dependency in you app/build.gradle file.

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

Currently the latest stable version is

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

Here you can find all the info the setup .

The reason why the MaterialComponents theme does not show is because you did not include the required Material Components library in your app/build.gradle :

dependencies {
    implementation 'com.google.android.material:material:<version>'
}

The currently available versions are listed on the project's GitHub releases .

Add the dependency on Android's Material in /android/app/build.gradle:

dependencies {
    // ...
    implementation 'com.google.android.material:material:<version>'
    // ...
}

To find out the latest version, visit Google Maven .

Set the theme in /android/app/src/main/res/values/styles.xml:

//<style name="LaunchTheme" parent="Theme.AppCompat"> - remove
<style name="LaunchTheme" parent="Theme.MaterialComponents.NoActionBar"> - add

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM