我使用Android Studio Arctic Fox创建了一个新的Android项目|2020.3.1补丁3和我的目标是简单地自定义我的应用程序使用Material 3主题
错误发生在values\themes.xml处,表示Cannot resolve symbol 'Theme.Material3.Light.NoActionBar'
我在这个问题上发现了一个类似的问题,但是'Theme.MaterialComponents.Light.NoActionBar'
是我创建项目时的默认主题,它没有错误,当我根据Migrating to Material Design 3章节 * 从M2迁移到M3(MDC 1.4.0到MDC 1.5.0)* 下的本文更改为使用Theme.Material3.Light.NoActionBar
时,错误开始了
我尝试过将项目与Gradle文件同步,使缓存无效/重新启动..但我仍然得到相同的错误
我已经使用Material Theme builder生成了我的themes.xml
和colors.xml
,下面是我的文件
主题文件.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>
构建版本.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'
}
建筑等级(项目)
// 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
}
4条答案
按热度按时间5jdjgkvh1#
您必须在Gradle文件中更改材料设计的依赖性。
注意:要使用新的Material 3主题和构件样式,必须依赖版本1.5.0-alpha 04或更高版本。
Getting started with MDC android
访问Google的Maven Repository或MVN Repository以查找该库的最新版本。
dsekswqp2#
你必须使用alpha版本的材料依赖
Alpha版本-这是您正在开发的功能不完整或部分完整时的版本。
更新您的物料相关性
到
e5nqia273#
1.从Gradle中删除:仅运行时组:'androidx. appcompat',名称:“appcompat”,版本:'1.7.0-alpha 01'实现'com.谷歌.安卓.材料:材料:1.7.0'
1.同步
1.添加:仅运行时组:'androidx. appcompat',名称:“appcompat”,版本:'1.7.0-alpha 01'实现'com.谷歌.安卓.材料:材料:1.7.0'
1.再次同步
b4wnujal4#