【问题标题】:appcompat_v7 error in eclipseeclipse中的appcompat_v7错误
【发布时间】:2014-10-30 15:05:54
【问题描述】:

我是 android 开发的新手。我创建了一个新项目,但同时也创建了 appcompat_v7。现在我的项目无法运行,因为 appcompat_v7 有错误。 该错误仅在以下行的appcompat_v7-> res-> values-v21-> style_base.xml中

<style name="Base.Widget.AppCompat.ActionButton"
           parent="android:Widget.Material.ActionButton">
  </style>

有说明

Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton'

我已尝试清理和重建项目,但错误仍然存​​在。如何解决此问题?

这里是 appcompat_v7 -> res -> values-v21 -> styles.xml 该文件是第 75 行出现错误的文件: 错误:

<style name="Base.Widget.AppCompat.ActionButton"
           parent="android:Widget.Material.ActionButton">
    </style>

这是文件

<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2014 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<resources>

    <!-- Like in themes_base.xml, the namespace "*.AppCompat.Base" is used to
     define base styles for the platform version. The "*.AppCompat"
     variants are for direct use or use as parent styles by the app. -->
    <eat-comment/>

    <style name="Base.Widget.AppCompat.ActionBar.TabView"
           parent="android:Widget.Material.ActionBar.TabView">
    </style>

    <style name="Base.Widget.AppCompat.Light.ActionBar.TabView"
           parent="android:Widget.Material.Light.ActionBar.TabView">
    </style>

    <style name="Base.Widget.AppCompat.ActionBar.TabText"
           parent="android:Widget.Material.ActionBar.TabText">
    </style>

    <style name="Base.Widget.AppCompat.Light.ActionBar.TabText"
           parent="android:Widget.Material.Light.ActionBar.TabText">
    </style>

    <style name="Base.Widget.AppCompat.Light.ActionBar.TabText.Inverse"
           parent="android:Widget.Material.Light.ActionBar.TabText">
    </style>

    <style name="Base.TextAppearance.AppCompat.Widget.ActionBar.Menu"
           parent="android:TextAppearance.Material.Widget.ActionBar.Menu">
    </style>

    <style name="Base.TextAppearance.AppCompat.Widget.ActionBar.Title"
           parent="android:TextAppearance.Material.Widget.ActionBar.Title">
    </style>

    <style name="Base.TextAppearance.AppCompat.Widget.ActionBar.Subtitle"
           parent="android:TextAppearance.Material.Widget.ActionBar.Subtitle">
    </style>

    <style name="Base.TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
           parent="android:TextAppearance.Material.Widget.ActionBar.Title.Inverse">
    </style>

    <style name="Base.TextAppearance.AppCompat.Widget.ActionBar.Subtitle.Inverse"
           parent="android:TextAppearance.Material.Widget.ActionBar.Subtitle.Inverse">
    </style>

    <style name="Base.TextAppearance.AppCompat.Widget.ActionMode.Title"
           parent="android:TextAppearance.Material.Widget.ActionMode.Title">
    </style>

    <style name="Base.TextAppearance.AppCompat.Widget.ActionMode.Subtitle"
           parent="android:TextAppearance.Material.Widget.ActionMode.Subtitle">
    </style>

    <!-- Action Button Styles -->

    <style name="Base.Widget.AppCompat.ActionButton"
           parent="android:Widget.Material.ActionButton">
    </style>

    <style name="Base.Widget.AppCompat.ActionButton.CloseMode"
           parent="android:Widget.Material.ActionButton.CloseMode">
    </style>

    <style name="Base.Widget.AppCompat.ActionButton.Overflow"
           parent="android:Widget.Material.ActionButton.Overflow">
    </style>

    <!--
        Widget.AppCompat.Toolbar style is purposely ommitted. This is because the support
        Toolbar implementation is used on ALL platforms and relies on the unbundled attrs.
        The supporting Toolbar styles below only use basic attrs so work fine.
    -->

    <style name="Base.Widget.AppCompat.Toolbar.Button.Navigation"
           parent="android:Widget.Material.Toolbar.Button.Navigation">
    </style>

    <style name="Base.TextAppearance.Widget.AppCompat.Toolbar.Title"
           parent="android:TextAppearance.Material.Widget.ActionBar.Title">
    </style>

    <style name="Base.TextAppearance.Widget.AppCompat.Toolbar.Subtitle"
           parent="android:TextAppearance.Material.Widget.ActionBar.Subtitle">
    </style>

    <!-- Spinner Widgets -->

    <style name="Base.Widget.AppCompat.ListView.DropDown"
           parent="android:Widget.Material.ListView.DropDown"/>

    <style name="Base.Widget.AppCompat.DropDownItem.Spinner"
           parent="android:Widget.Material.DropDownItem.Spinner"/>

    <style name="Base.Widget.AppCompat.Spinner" parent="android:Widget.Material.Spinner" />

    <style name="Base.Widget.AppCompat.Spinner.DropDown.ActionBar" parent="android:Widget.Material.Spinner">
        <item name="spinnerMode">dropdown</item>
        <item name="disableChildrenWhenDisabled">true</item>
        <item name="popupPromptView">@layout/abc_simple_dropdown_hint</item>
    </style>

    <style name="Base.Widget.AppCompat.ListView.Menu"
           parent="android:Widget.Material.ListView" />

    <!-- Popup Menu -->

    <style name="Base.Widget.AppCompat.ListPopupWindow" parent="android:Widget.Material.ListPopupWindow">
    </style>

    <style name="Base.Widget.AppCompat.PopupMenu" parent="android:Widget.Material.PopupMenu">
    </style>

    <style name="Base.Widget.AppCompat.Light.PopupMenu"
        parent="android:Widget.Material.Light.PopupMenu">
    </style>

    <style name="Base.Widget.AppCompat.PopupMenu.Overflow">
        <item name="android:dropDownHorizontalOffset">-4dip</item>
        <item name="android:overlapAnchor">true</item>
    </style>

    <style name="Base.Widget.AppCompat.Light.PopupMenu.Overflow">
        <item name="android:dropDownHorizontalOffset">-4dip</item>
        <item name="android:overlapAnchor">true</item>
    </style>

    <style name="Base.TextAppearance.AppCompat.Widget.PopupMenu.Large"
        parent="android:TextAppearance.Material.Widget.PopupMenu.Large">
    </style>

    <style name="Base.TextAppearance.AppCompat.Widget.PopupMenu.Small"
        parent="android:TextAppearance.Material.Widget.PopupMenu.Small">
    </style>

    <style name="Base.TextAppearance.AppCompat.Light.Widget.PopupMenu.Large"
        parent="android:TextAppearance.Material.Widget.PopupMenu.Large">
    </style>

    <style name="Base.TextAppearance.AppCompat.Light.Widget.PopupMenu.Small"
        parent="android:TextAppearance.Material.Widget.PopupMenu.Small">
    </style>

    <!-- Search View result styles -->

    <style name="Base.TextAppearance.AppCompat.SearchResult.Title"
           parent="@android:TextAppearance.Material.SearchResult.Title">
    </style>

    <style name="Base.TextAppearance.AppCompat.SearchResult.Subtitle"
           parent="@android:TextAppearance.Material.SearchResult.Subtitle">
    </style>

    <style name="Base.Widget.AppCompat.AutoCompleteTextView" parent="android:Widget.Material.AutoCompleteTextView" />

    <style name="Base.Widget.AppCompat.Light.AutoCompleteTextView" parent="android:Widget.Material.AutoCompleteTextView" />

    <!-- Progress Bar -->

    <style name="Base.Widget.AppCompat.ProgressBar.Horizontal"
           parent="android:Widget.Material.ProgressBar.Horizontal">
    </style>

    <style name="Base.Widget.AppCompat.ProgressBar"
           parent="android:Widget.Material.ProgressBar">
    </style>

    <!-- TODO. Needs updating for Material -->
    <style name="Base.Widget.AppCompat.ActivityChooserView" parent="">
        <item name="android:gravity">center</item>
        <item name="android:background">@drawable/abc_ab_share_pack_holo_dark</item>
        <item name="android:divider">?attr/dividerVertical</item>
        <item name="android:showDividers">middle</item>
        <item name="android:dividerPadding">6dip</item>
    </style>

</resources>

这是我的项目 -> res -> values -> styles.xml

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

【问题讨论】:

  • @Funkystein 我也试过了。但我又得到了同样的错误,因为以下样式标签包含相同的父属性值,我不热衷于删除所有样式标签,因为它们是操作按钮,我以后可能会在项目中遇到问题。

标签: java android eclipse adt


【解决方案1】:

别人也有同样的问题,你需要安装Java 1.8

查看此链接:https://stackoverflow.com/a/26642124/2767703

【讨论】:

  • 您能否指定如何将 Theme.AppCompat 和 Widget.AppCompat 添加到我的 styles.xml 文件中,因为安装 Java 8 对我不起作用:(
  • 查看此链接:android-developers.blogspot.nl/2014/10/… 转到章节主题。父级应该是:Theme.AppCompat.Light 或使用 darkactionbar。如果您仍然无法使其正常工作,请添加您的整个 styles.xml 并再次发表评论。
  • @cyclops 首先,我建议切换到 Android Studio。效果很好!但如果你仍然想要 Eclipse 试试这个:转到项目属性(右键单击项目 -> 属性) -> Java 编译器并将 JDK 更改为 1.8(如果这不可见,请尝试 1.7 或再次下载 JDK 1.8)
  • 谢谢,我会试试的
【解决方案2】:

检查您的项目和 appcompat 中的构建目标。您的项目不得低于 appcompat 的目标,我认为需要 SDK 10 或更高版本:

在 Eclipse 中转到 Project->Properties->Android (Project Build Target)

【讨论】:

  • 我检查了。两者都设置为 Android 4.4.2 API 19
【解决方案3】:

Android Lollipop 启动后,eclipse 和 sdk manager 也升级了,但是

SDK 5.0(Lollipop) 存在关于 v7 (appcompat, cardview ...) 的问题 - 未找到资源或匹配。

这个链接

Using android.support.v7.widget.CardView in my project (Eclipse)

http://happilycoded.com/blog/using-recyclerview-and-cardview-in-eclipse-adt/

或者这会帮助你

【讨论】:

    【解决方案4】:

    为了解决这个问题,

    1. 右键单击 appcompat_v7 库并选择属性
    2. 点击安卓选项,
    3. 将项目构建路径设置为 Android 5.0(API 级别 21)
    4. 应用更改。
    5. 转到 project.properties appcompat_v7 库下的文件,
    6. 将项目目标设置为:target=android-21
    7. 清理 + 构建 appcompat_v7 库和您的项目

    here

    【讨论】:

      【解决方案5】:

      右键单击 appcompat 项目文件夹并打开“属性”。 转到“Android”部分并选中“Android 5.0”作为项目构建目标 应用它并享受:)

      【讨论】:

        【解决方案6】:

        希望这种方法对您有所帮助。

        appcompat v7的project.properties文件更新为:target=android-19target=android-23。 始终以更高版本为目标。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-11-27
          • 1970-01-01
          • 1970-01-01
          • 2015-10-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多