android - 膨胀类 android.support.v7.widget.Toolbar 时出错。我的错误或错误?

标签 android android-studio android-support-library android-appcompat android-styles

在使用 SDK 22 预览布局时,我的所有布局都出现了以下渲染问题。

Error inflating class android.support.v7.widget.Toolbar.

java.lang.NoSuchFieldError: View_theme

在我的例子中,问题是 styles.xml:

存在渲染问题的 XML:

<resources>

    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar" />
    <!-- Base application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/accent</item>
        <item name="android:textColorPrimary">@color/primary_text</item>
    </style>

</resources>

没有问题的 XML:

<resources>

    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar" />
    <!-- Base application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/accent</item>
        <item name="android:textColorPrimary">@color/primary_text</item>
    </style>

</resources>

请注意我必须如何在父引用中添加 @style/。这似乎解决了我的问题(重建后)。

问题,这是我这边的错误,还是bug?很多教程都没有放(Including Official Android Page)

Gradle :

compileSdkVersion 22
buildToolsVersion '22.0.1'
minSdkVersion 15
targetSdkVersion 22
classpath 'com.android.tools.build:gradle:1.1.0'

最后说明:我没有使用工具栏。

最佳答案

编辑:

从另一个阅读SO question .

如果您的 Activity 扩展AppCompactActivity,您的父主题应该是

<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar" />

如果使用 ActionBarActivity,主题应该是

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

I think the difference is on purpose, and not a bug. Please feel free to correct me if i am wrong as i cannot conferm the same from anywhere yet.

旧:

要将工具栏用作操作栏,您需要做的第一件事是禁用装饰提供的操作栏。最简单的方法是让您的主题从 Theme.AppCompat.NoActionBar(或轻型变体)扩展。

使用:

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar" />

From this post.

关于android - 膨胀类 android.support.v7.widget.Toolbar 时出错。我的错误或错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29867476/

相关文章:

android - 有没有办法更改模拟器的默认启动位置?

android-studio - Android Studio :disable "never used" warning on methods that I want to use later

android - (Android Studio)快速完成外部类的建议变量名?

android - 无法解析符号 'ViewCompat'

android - 如何使用支持库 26 在 AlertDialog 中设置自定义字体

android - 案例变体存在吗?

java - 错误 : androidmanifest. xml 文件丢失 --> 我错过了什么?

java - 如何在 Android 上获取联系人的名字和姓氏列表?

android - 未找到 Material 小部件 文本字段小部件需要 Material 小部件祖先

android - 当 tabMode 设置为 'scrollable' 时,TabLayout 不填充宽度