错误充气类android.support.v7.widget.Toolbar。我的错误或缺陷? [英] Error inflating class android.support.v7.widget.Toolbar. My mistake or bug?

查看:974
本文介绍了错误充气类android.support.v7.widget.Toolbar。我的错误或缺陷?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用SDK 22时preVIEW他们对我的所有布局以下渲染问题。


  

错误充气类android.support.v7.widget.Toolbar。


  
  

java.lang.NoSuchFieldError:View_theme


在我的情况下,这个问题是 styles.xml

XML与3D渲染问题:

 <资源>    <样式名称=AppBaseTheme父=Theme.AppCompat.Light.DarkActionBar/>
    <! - Base应用程序的主题。 - >
    <样式名称=AppTheme父=AppBaseTheme>
        <项目名称=colorPrimary> @彩色/初级与LT; /项目>
        <项目名称=colorPrimaryDark> @彩色/ primary_dark< /项目>
        <项目名称=colorAccent> @颜色/重音< /项目>
        <项目名称=机器人:textColorPrimary> @彩色/ primary_text< /项目>
    < /风格>< /资源>

XML没有问题:

 <资源>    <样式名称=AppBaseTheme父=@风格/ Theme.AppCompat.Light.DarkActionBar/>
    <! - Base应用程序的主题。 - >
    <样式名称=AppTheme父=AppBaseTheme>
        <项目名称=colorPrimary> @彩色/初级与LT; /项目>
        <项目名称=colorPrimaryDark> @彩色/ primary_dark< /项目>
        <项目名称=colorAccent> @颜色/重音< /项目>
        <项目名称=机器人:textColorPrimary> @彩色/ primary_text< /项目>
    < /风格>< /资源>

注意我是如何不得不添加 @style / 父参考。这似乎解决我的问题(重建后)。

问,这是在我的身边错误或缺陷?许多教程,不要把它(的Including官方Android页

摇篮:

  compileSdkVersion 22
buildToolsVersion '22 .0.1
15的minSdkVersion
targetSdkVersion 22
类路径'com.android.tools.build:gradle:1.1.0

最后请注意:我不使用工具栏


解决方案

编辑:

从另一个

阅读<一href=\"http://stackoverflow.com/questions/17870881/cant-find-theme-appcompat-light-for-new-android-actionbar-support\">SO问题。

如果您的活动来延长 AppCompactActivity ,你的父母的主题应该是

 &LT;样式名称=AppBaseTheme父=@风格/ Theme.AppCompat.Light.DarkActionBar/&GT;

作为的地方,如果用 ActionBarActivity ,主题应该是

 &LT;样式名称=AppBaseTheme父=Theme.AppCompat.Light.DarkActionBar/&GT;


  

我觉得不同的是有目的的,而不是一个错误。请随时
  纠正我,如果我错了,因为我不能从任何地方conferm相同
  然而。


OLD:

要使用工具栏作为行动起来吧,你需要做的第一件事是禁用的装饰提供了操作栏。最简单的方法是让你的主题从Theme.AppCompat.NoActionBar(或光变)扩展。

使用:

 &LT;样式名称=AppBaseTheme父=Theme.AppCompat.Light.NoActionBar/&GT;

从这个职位。

I had the following rendering issue on all my layouts when using SDK 22 to preview them.

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

java.lang.NoSuchFieldError: View_theme

In my case , the problem was styles.xml:

XML with rendering problem:

<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 without problem:

<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>

Notice how I had to add @style/ in the parent reference. That seems to solve my problem (after a rebuild).

Question, is this an error on my side, or a bug? Many tutorials don't put it (Including Official Android Page)

Gradle:

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

Final Note: I'm not using Toolbar.

解决方案

EDIT :

Reading from another SO question.

If your activity extends AppCompactActivity, your parent theme should be

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

where as, if using ActionBarActivity, theme should be

<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.

OLD :

To use Toolbar as an action bar, the first thing you need to do is disable the decor provided action bar. The easiest way is to have your theme extend from Theme.AppCompat.NoActionBar (or the light variant).

Use :

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

From this post.

这篇关于错误充气类android.support.v7.widget.Toolbar。我的错误或缺陷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆