在当前主题中找不到样式...

Failed to find style ... in current theme

我在 android 工作室工作期间遇到了一个可疑的错误。 每次我启动工作室并创建一个新项目时,都会出现另一个渲染错误

Failed to load AppCompat ActionBar with unknown error.

不是很明白是什么意思,不过替换一下就好办了

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">  

至:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

但每次我向布局添加新元素时,都会出现错误

Failed to find style ... in current theme

我找到了一个 solution,它几乎帮助了除我以外的所有人。但是现在改变主题并不能解决问题。

如果有人知道如何处理它,请帮助。

在您的应用 gradle 下的依赖项中使用此:

implementation 'com.android.support:appcompat-v7:28.0.0-rc01'

如果你还没有。

您可以复制样式名称 floatingactionbuttonstyle 并将其包含在您的应用主题中。

添加这一行

<item name="floatingActionButtonStyle">@style/Widget.Design.FloatingActionButton</item>

最后的主题是这样的

   <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="floatingActionButtonStyle">@style/Widget.Design.FloatingActionButton</item>

</style>

Just add the style name when error occured in layout editor & add the responding styles.

这里添加了其他一些元素的样式。

   <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="chipStyle">@style/Base.Widget.MaterialComponents.Chip</item>
    <item name="chipGroupStyle">@style/Widget.MaterialComponents.ChipGroup</item>
    <item name="bottomNavigationStyle">@style/Widget.Design.BottomNavigationView</item>
    <item name="coordinatorLayoutStyle">@style/Widget.Support.CoordinatorLayout</item>
    <item name="bottomAppBarStyle">@style/Widget.MaterialComponents.BottomAppBar</item>
    <item name="floatingActionButtonStyle">@style/Widget.Design.FloatingActionButton</item>
</style>

您可以使用样式名称添加默认样式。然后你解决这个错误。