gpt4 book ai didi

android - 无法解析符号 'Theme.Material3.Light.NoActionBar' (Android Studio)

转载 作者:行者123 更新时间:2023-12-04 23:53:22 24 4
gpt4 key购买 nike

我使用 Android Studio 北极狐创建了一个新的 Android 项目 | 2020.3.1 补丁 3,我的目标是简单地自定义我的应用程序以使用 Material3 主题
错误发生在 值\themes.xml Cannot resolve symbol 'Theme.Material3.Light.NoActionBar'我在这个 Question 上发现了一个类似的问题但是 'Theme.MaterialComponents.Light.NoActionBar'是我创建项目时的默认主题并且没有错误,当我更改为使用 Theme.Material3.Light.NoActionBar 时开始出现错误根据这篇关于 Migrating to Material Design 3 的文章在从 M2 迁移到 M3(MDC 1.4.0 到 MDC 1.5.0)部分下
我已经尝试使用 gradle 文件同步项目,使缓存/重新启动无效.. 但我仍然得到同样的错误
我用过Material Theme builder生成我的themes.xmlcolors.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>
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 RepositoryMVN Repository找到最新版本的库。

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com