【问题标题】:Theme Error - how to fix?主题错误 - 如何修复?
【发布时间】:2019-01-31 16:42:39
【问题描述】:

尝试了许多解决方案,但没有任何帮助

参考:Failed to find style 'coordinatorLayoutStyle' in current theme

但没有帮助

渲染问题:

在当前主题中找不到样式“coordinatorLayoutStyle”

提示:尝试刷新布局。

我的项目的build.gradle文件是:

buildscript {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.4'


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

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

模块:应用程序

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "*****"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:design:28.0.0-alpha1'
}

主要活动 XML 代码

    <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.design.bottomappbar.BottomAppBar
        android:id="@+id/bar"
        style="@style/Widget.MaterialComponents.BottomAppBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        app:navigationIcon="@drawable/ic_menu"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:fabAttached="true"
        app:backgroundTint="@color/colorPrimary"
        app:fabCradleVerticalOffset="12dp"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_anchor="@id/bar"/>

</android.support.design.widget.CoordinatorLayout>

为什么我不将已编译的 SDK 版本 28 更改为 27 bcz 我想使用底部应用栏

Bottom App Bar Material Design

App Bars:Bottom- Material Design

【问题讨论】:

  • 把这个库implementation 'com.android.support:design:27.1.1'也添加到你的module:app中,分别对应你的sdk
  • 也许这与最新的支持库版本有关,尽管我不太确定。所以尝试将当前版本替换为 27.1.1 并查看它是否有效。 compileSdkVersion 27 targetSdkVersion 27 和 implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:design:27.1.1'
  • 当我改变了设计和适用的版本时
  • 错误:找不到资源样式/Widget.MaterialComponents.BottomAppBar(又名 *.appbar:style/Widget.MaterialComponents.BottomAppBar)。消息{kind=ERROR, text=error: resource style/Widget.MaterialComponents.BottomAppBar (aka **.appbar:style/Widget.MaterialComponents.BottomAppBar) not found., sources=[/home/android/Desktop/Android Studio Projects /Appbar/app/src/main/res/layout/activity_main.xml:10],原始消息=,工具名称=Optional.of(AAPT)}
  • 发生这种情况是因为 Material Components 尚未发布依赖版本 27 下的新版本。因此,如果您想访问最新的更改,您必须将您想要的材料组件库部分直接复制到您的项目中。

标签: java android android-coordinatorlayout android-appbarlayout


【解决方案1】:

这是 28.0.0 中的一个错误,唯一的修复(解决方法)是将其添加到您的 Build.gradle

configurations.all {
        resolutionStrategy.eachDependency { DependencyResolveDetails details ->
            def requested = details.requested
            if (requested.group == "com.android.support") {
                if (!requested.name.startsWith("multidex")) {
                    details.useVersion "27.1.1"
                }
            }
        }
    }

不知何故,这绕过了问题并为此使用了 27 个支持库。否则,您可能想将您的 Android Studio 更新为金丝雀频道版本或使用 27.1.1 等向后支持库。

【讨论】:

  • Android 工作室已更新到金丝雀频道 virsion 谢谢
  • 我尝试了 5 个解决方案,这是唯一对我有用的解决方案
【解决方案2】:

此错误发生在您的渲染布局中,它是 Studio 的一部分,不在任何文件或库中

  1. 尝试在 styles.xml 中的 Theme 之前添加“Base”,如下所示:- "Base.Theme.AppCompat.Light.DarkActionBar"

  2. 请通过选择菜单选项“文件”重新启动 Android Studio → “使缓存无效/重新启动”

  3. 解决方法:尝试使用 AS v1.3 预览通过 M 预览进行渲染或 使用 FrameLayout 进行设计和更改 android.support.design.widget.CoordinatorLayout 同时调试。

【讨论】:

  • 仍然无法正常工作我已经尝试过这个解决方案 Invalidate Caches/ Restart
  • 尝试将实现 'com.android.support:design:28.0.0-alpha1' 替换为实现 'com.android.support:design:28.0.0-alpha3'
  • 之后清理并重建项目
  • 仍然无法尝试实现 'com.android.support:design:28.0.0-alpha3'
猜你喜欢
  • 2022-10-24
  • 2016-11-29
  • 2020-09-05
  • 1970-01-01
  • 2014-06-10
  • 2021-07-07
  • 2020-12-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多