android 工作室渲染 'coordinatorLayoutStyle' 的新问题

New android studio rendering issue with 'coordinatorLayoutStyle'

我有 android 工作室,非常完美,没有任何问题。一切正常,直到我重新安装 windows 以使 PC 更快一些。然后我安装了最新的 android studio。虽然最后一个也是最新的,但完全没有问题。但是,在新的 android 工作室中,我启动的任何项目或我打开的任何具有 constraintLaoyout 的项目,xml 的设计视图都会遇到以下错误。

Rendering Problem

Failed to find style 'coordinatorLayoutStyle' in current theme

当我在我的 activity

上放置任何小部件或任何东西时出现第二个错误

Missing Constraints in ConstraintLayout

This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime unless you add the constraints The layout editor allows you to place widgets anywhere on the canvas, and it records the current position with designtime attributes (such as layout_editor_absoluteX). These attributes are not applied at runtime, so if you push your layout on a device, the widgets may appear in a different location than shown in the editor. To fix this, make sure a widget has both horizontal and vertical constraints by dragging from the edge connections.

首先,更新您的项目以使用最新的构建版本。当涉及到大多数 Android 视图时,这有助于解决很多问题。

其次,转到您的样式并添加这行代码以修复第一个错误

<item name="coordinatorLayoutStyle">@style/Widget.Design.CoordinatorLayout</item>

第三,CoordinaterLayout的children一定要加约束,如果你是这个布局的新手,可以切换到RelativeLayout也可以使用设计视图添加约束。查看官方文档here

关于约束的有用视频HERE

您是否尝试过在 build.gradle 中添加设计库? 如果没有,则只需添加它 实施 'com.android.support:design:23.2.0'

我发现 build.graddle(Module: app) 中的依赖项的实现是 API 28 但在以下目录中只有 API 26

C:\Users\[username]\AppData\Local\Android\Sdk\extras\android\m2repository\com\android\support\appcompat-v7

所以我删除了所有 SDK 平台和构建工具,并在 SDK 管理器(select Show Package Details)中使用 API 26 安装它们。 然后我开始了新项目。 API26制作的项目没有渲染问题。

问题终于解决了。写下这个答案,以便其他人可以从类似的问题中得到帮助。

默认情况下,当我们在 android studio 中创建新项目时,它使用来自 SDK 的最新 API。在我的例子中是 API 28。但是,API 28 不完整或部分安装。我尝试完全安装 API 28,但由于某种原因它不起作用。然后我删除了 API 28 并安装了最新的 API 27。通过在我创建或打开任何使用 API 27 的新项目并在其中获取所有必需的东西时执行此操作。这就是我解决问题的方法。

感谢所有试图帮助我的人。