【问题标题】:Android Studio Rendering Problems - Missing styles?Android Studio 渲染问题 - 缺少样式?
【发布时间】:2016-03-08 16:04:54
【问题描述】:

我在Android StudioPreview 窗口中收到以下错误:

渲染问题缺少样式。是否选择了正确的主题 这个布局?使用布局上方的主题组合框选择一个 不同的布局,或修复主题样式引用。找不到 当前主题中的“?attr/actionBarPopupTheme”。 (4个类似的错误不是 显示)

我创建了一个自定义样式/主题。这是关于styles.xml

<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
        <item name="android:actionBarStyle"   tools:ignore="NewApi">@style/MyActionBar</item>
        <item name="actionBarStyle">@style/MyActionBar</item>
        <item name="actionBarTheme">@style/MyActionBarTheme</item>
    </style>

    <style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:background"  tools:ignore="NewApi">@color/white</item>
        <item name="titleTextStyle">@style/MyActionBar.ActionBar.TitleTextStyle</item>
        <item name="background">@color/bg_common</item>
    </style>

    <style name="MyActionBarTheme" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="actionMenuTextColor">@color/title</item>
        <item name="colorControlNormal">@color/title</item>
    </style>

    <style name="MyActionBar.ActionBar.TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/title</item>
    </style>
</resources>

我的布局文件头是这样的:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    style="@style/CustomActionBarTheme"
    android:id="@+id/drawer_layout"
    android:background="@color/bg_common_2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

...

在我的清单文件中,我已经在应用程序标签中添加了:

android:theme="@style/CustomActionBarTheme" 

为什么我会收到错误消息?我还在我的预览窗口中选择了CustomActionBarTheme 作为主题。我错过了什么吗?提前感谢您的任何建议!

【问题讨论】:

  • 尝试将 SDK 预览版更改为旧版本
  • 谢谢!将 API 级别从 23 设置为 22 会有所帮助。您可以将此添加为我的问题的答案,我会将其设置为确认答案:-)

标签: java android xml android-studio


【解决方案1】:

Android Studio 使用最新安装的 SDK 来预览布局文件。由于缺少样式,这可能会导致预览错误 - 切换到较旧的 API 级别(例如从 23 到 22)可以解决此问题。

【讨论】:

    【解决方案2】:

    另一种方法是更改​​布局主题(靠近 SDK 预览版按钮) 工作正常

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多