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



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

膨胀类 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/。这似乎解决了我的问题(重建后)。

问题,这是我这边的错误,还是错误?很多教程都没放过(包括安卓官方页面)

格拉德尔:

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

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

编辑 :

从另一个 SO 问题中阅读。

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

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

其中,如果使用ActionBarActivity,主题应该是

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

我认为区别是故意的,而不是错误。请随意 如果我错了,请纠正我,因为我无法从任何地方进行相同的讨论 还。

老:

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

用:

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

从这篇文章。

就我而言,解决方案非常简单

  1. @style添加到父主题

    <style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
    
  2. Toolbar中删除android.support.v7.widget.

  3. app:theme移动到android:theme

    <Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
    

相关内容

最新更新