无法解析符号 'Theme.Material3.Light.NoActionBar' (Android Studio)
Cannot resolve symbol 'Theme.Material3.Light.NoActionBar' (Android Studio)
我使用 Android Studio Arctic Fox 创建了一个新的 Android 项目 | 2020.3.1 补丁 3,我的目标是简单地自定义我的应用程序以使用 Material3 主题
错误发生在 values\themes。xml 说 Cannot resolve symbol 'Theme.Material3.Light.NoActionBar'
我在Migrating from M2 to M3 (MDC 1.4.0 to MDC 1.5.0)[=22]部分下发现了一个类似的问题 but 'Theme.MaterialComponents.Light.NoActionBar'
was my default theme when i created the project and it had no errors, the error started when i changed to use Theme.Material3.Light.NoActionBar
as per this article on Migrating to Material Design 3 =]
我已经尝试使用 gradle 个文件同步项目,使缓存无效/重新启动..但我仍然遇到相同的错误
我已经使用 Material Theme builder 生成了我的 themes.xml
和 colors.xml
,下面是我的文件
themes.xml
<resources>
<style name="Theme.App" parent="Theme.Material3.Light.NoActionBar">
<item name="colorPrimary">@color/md_theme_light_primary</item>
<item name="colorOnPrimary">@color/md_theme_light_onPrimary</item>
<item name="colorPrimaryContainer">@color/md_theme_light_primaryContainer</item>
<item name="colorOnPrimaryContainer">@color/md_theme_light_onPrimaryContainer</item>
<item name="colorSecondary">@color/md_theme_light_secondary</item>
<item name="colorOnSecondary">@color/md_theme_light_onSecondary</item>
<item name="colorSecondaryContainer">@color/md_theme_light_secondaryContainer</item>
<item name="colorOnSecondaryContainer">@color/md_theme_light_onSecondaryContainer</item>
<item name="colorTertiary">@color/md_theme_light_tertiary</item>
<item name="colorOnTertiary">@color/md_theme_light_onTertiary</item>
<item name="colorTertiaryContainer">@color/md_theme_light_tertiaryContainer</item>
<item name="colorOnTertiaryContainer">@color/md_theme_light_onTertiaryContainer</item>
<item name="colorError">@color/md_theme_light_error</item>
<item name="colorErrorContainer">@color/md_theme_light_errorContainer</item>
<item name="colorOnError">@color/md_theme_light_onError</item>
<item name="colorOnErrorContainer">@color/md_theme_light_onErrorContainer</item>
<item name="android:colorBackground">@color/md_theme_light_background</item>
<item name="colorOnBackground">@color/md_theme_light_onBackground</item>
<item name="colorSurface">@color/md_theme_light_surface</item>
<item name="colorOnSurface">@color/md_theme_light_onSurface</item>
<item name="colorSurfaceVariant">@color/md_theme_light_surfaceVariant</item>
<item name="colorOnSurfaceVariant">@color/md_theme_light_onSurfaceVariant</item>
<item name="colorOutline">@color/md_theme_light_outline</item>
<item name="colorOnSurfaceInverse">@color/md_theme_light_inverseOnSurface</item>
<item name="colorSurfaceInverse">@color/md_theme_light_inverseSurface</item>
<item name="colorPrimaryInverse">@color/md_theme_light_primaryInverse</item>
</style>
</resources>
build.gradle(应用程序)
plugins {
id 'com.android.application'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.blablabla"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion '32.0.0 rc1'
}
dependencies {
implementation 'androidx.compose.material3:material3:1.0.0-alpha02'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
testImplementation 'junit:junit:'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
buid.gradle(项目)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
您必须在 gradle 文件中更改 material 设计的依赖项。
Note: In order to use the new Material3 themes and component styles, you must depend on version 1.5.0-alpha04 or later.
Getting started with MDC android
访问 Google's Maven Repository or MVN Repository 查找最新版本的库。
您必须使用 material 依赖项的 alpha 版本
Alpha 版本 - 这是您正在开发的功能未完成或部分完成时的版本。
更新您的 material 依赖项
implementation 'com.google.android.material:material:1.4.0'
至
implementation 'com.google.android.material:material:1.6.0-alpha01'
我使用 Android Studio Arctic Fox 创建了一个新的 Android 项目 | 2020.3.1 补丁 3,我的目标是简单地自定义我的应用程序以使用 Material3 主题
错误发生在 values\themes。xml 说 Cannot resolve symbol 'Theme.Material3.Light.NoActionBar'
我在Migrating from M2 to M3 (MDC 1.4.0 to MDC 1.5.0)[=22]部分下发现了一个类似的问题 我已经尝试使用 gradle 个文件同步项目,使缓存无效/重新启动..但我仍然遇到相同的错误 我已经使用 Material Theme builder 生成了我的 themes.xml build.gradle(应用程序) buid.gradle(项目)'Theme.MaterialComponents.Light.NoActionBar'
was my default theme when i created the project and it had no errors, the error started when i changed to use Theme.Material3.Light.NoActionBar
as per this article on Migrating to Material Design 3 =]
themes.xml
和 colors.xml
,下面是我的文件 <resources>
<style name="Theme.App" parent="Theme.Material3.Light.NoActionBar">
<item name="colorPrimary">@color/md_theme_light_primary</item>
<item name="colorOnPrimary">@color/md_theme_light_onPrimary</item>
<item name="colorPrimaryContainer">@color/md_theme_light_primaryContainer</item>
<item name="colorOnPrimaryContainer">@color/md_theme_light_onPrimaryContainer</item>
<item name="colorSecondary">@color/md_theme_light_secondary</item>
<item name="colorOnSecondary">@color/md_theme_light_onSecondary</item>
<item name="colorSecondaryContainer">@color/md_theme_light_secondaryContainer</item>
<item name="colorOnSecondaryContainer">@color/md_theme_light_onSecondaryContainer</item>
<item name="colorTertiary">@color/md_theme_light_tertiary</item>
<item name="colorOnTertiary">@color/md_theme_light_onTertiary</item>
<item name="colorTertiaryContainer">@color/md_theme_light_tertiaryContainer</item>
<item name="colorOnTertiaryContainer">@color/md_theme_light_onTertiaryContainer</item>
<item name="colorError">@color/md_theme_light_error</item>
<item name="colorErrorContainer">@color/md_theme_light_errorContainer</item>
<item name="colorOnError">@color/md_theme_light_onError</item>
<item name="colorOnErrorContainer">@color/md_theme_light_onErrorContainer</item>
<item name="android:colorBackground">@color/md_theme_light_background</item>
<item name="colorOnBackground">@color/md_theme_light_onBackground</item>
<item name="colorSurface">@color/md_theme_light_surface</item>
<item name="colorOnSurface">@color/md_theme_light_onSurface</item>
<item name="colorSurfaceVariant">@color/md_theme_light_surfaceVariant</item>
<item name="colorOnSurfaceVariant">@color/md_theme_light_onSurfaceVariant</item>
<item name="colorOutline">@color/md_theme_light_outline</item>
<item name="colorOnSurfaceInverse">@color/md_theme_light_inverseOnSurface</item>
<item name="colorSurfaceInverse">@color/md_theme_light_inverseSurface</item>
<item name="colorPrimaryInverse">@color/md_theme_light_primaryInverse</item>
</style>
</resources>
plugins {
id 'com.android.application'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.blablabla"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion '32.0.0 rc1'
}
dependencies {
implementation 'androidx.compose.material3:material3:1.0.0-alpha02'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
testImplementation 'junit:junit:'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
您必须在 gradle 文件中更改 material 设计的依赖项。
Note: In order to use the new Material3 themes and component styles, you must depend on version 1.5.0-alpha04 or later.
Getting started with MDC android
访问 Google's Maven Repository or MVN Repository 查找最新版本的库。
您必须使用 material 依赖项的 alpha 版本
Alpha 版本 - 这是您正在开发的功能未完成或部分完成时的版本。
更新您的 material 依赖项
implementation 'com.google.android.material:material:1.4.0'
至
implementation 'com.google.android.material:material:1.6.0-alpha01'