Android Studio渲染问题-缺少样式? [英] Android Studio Rendering Problems - Missing styles?
问题描述
我在 Android Studio
的 Preview
窗口中收到以下错误:
I get following error in the Preview
window of Android Studio
:
渲染问题缺少样式.是否选择了正确的主题这种布局?使用布局上方的主题组合框选择一个不同的布局,或修复主题样式引用.找不到当前主题中的?attr/actionBarPopupTheme".(4)类似错误不显示)
Rendering Problems Missing styles. Is the correct theme chosen for this layout? Use the Theme combo box above the layout to choose a different layout, or fix the theme style references. Failed to find '?attr/actionBarPopupTheme' in current theme. (4 similar errors not shown)
我创建了一个自定义样式/主题.这是关于 styles.xml
:
I have created a custom style/theme. This is the regarding 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>
我的布局文件标题如下:
My layout file header looks like this:
<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">
...
在清单文件中,我添加了application标记:
And in my manifest file I have added in the application tag:
android:theme="@style/CustomActionBarTheme"
为什么会出现错误?我还在预览窗口中选择了 CustomActionBarTheme
作为主题.我想念什么吗?感谢您提前提出任何建议!
Why do I get the error? I also choosed CustomActionBarTheme
in my Preview windows as Theme. Am I missing something? Thanks for any advice in advance!
推荐答案
Android Studio使用已安装的最新SDK来预览布局文件.由于缺少样式,这可能会导致预览错误-切换到较旧的API级别(例如,从23更改为22)可以解决此问题.
Android Studio uses the latest SDK installed to preview layout files. This can lead to preview errors due to missing styles - switching to an older API level (e.g. from 23 to 22) can fix this.
这篇关于Android Studio渲染问题-缺少样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!