【问题标题】:No resource identifier found for attribute 'showAsAction' in package 'android'在包“android”中找不到属性“showAsAction”的资源标识符
【发布时间】:2012-12-03 04:11:51
【问题描述】:

正如标题所示,我在至少 3 个 XML 布局文件中遇到了该错误,但是,我在任何这些 XML 文件中都没有看到 attritube“showsAsAction”,是我遗漏了什么还是我只是瞎了眼?,这里是有问题的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/findSelected"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Registrar Asistencia" 
        android:onClick="registrarAsistencia"/>

     <ListView 
         android:id="@+id/listaAlumnos" 
         android:layout_width="fill_parent"
         android:layout_height="fill_parent" />

</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center|top"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/lblCuenta"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Cuenta"
        android:textAppearance="?android:attr/textAppearanceLarge" />


    <EditText
        android:id="@+id/txtCuenta"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10" /> 

    <TextView
        android:id="@+id/lblPass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Contraseña"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/txtPass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/btnIniciarSesion"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="iniciarSesion"
        android:text="Iniciar Sesion" />

</LinearLayout>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

另外,我使用 Android 2.2 (API 8) 作为目标版本。我知道“showAsAction”是在 API 11 中实现的,但我在这里找不到问题。

更新:问题面板显示以下错误:

生成最终存档时出错:java.io.FileNotFoundException: C:\Users\\Documents\Android\Registro de Asistencia\bin\resources.ap_ 不存在

【问题讨论】:

  • @BinoyBabu 感谢您的回答。试过但不幸的是没有用。事实上,我不知道为什么,但每次我尝试清理项目时,R.java 文件都会被删除,并且似乎不会再次自动生成。幸运的是,我有项目文件夹的备份。关于它可能是什么的任何想法?
  • 可能是 ADT 插件或 Android SDK 损坏。尝试重新安装两者。
  • 项目中的错误。检查错误面板。应该告诉你警告和错误。重新安装所有东西是很痛苦的......首先检查隐藏的错误。
  • 检查问题面板(窗口->显示视图->问题)
  • 确实有 2 个错误,我已经用它们更新了 OP。

标签: java android android-xml android-menu


【解决方案1】:

当我忘记将 appcompat-v7:+ 添加到我的项目依赖项时,我遇到了这个问题。你可以在 build.gradle 中这样做:

dependencies {
  compile 'com.android.support:appcompat-v7:+'
}

这是因为我的 menu.xml 中有以下内容:

xmlns:app="http://schemas.android.com/apk/res-auto"

app:showAsAction="never"

当我删除 xmlns:app 命名空间并仅使用 android:showAsAction="never" 时,我不再需要 appcompat-v7 库。

【讨论】:

  • 这里说必须为 showAction developer.android.com/guide/topics/ui/actionbar.html 使用自定义命名空间@
  • 是的,我想这在旧设备上是有意义的。
  • 我有相反的方式 - Studio 为 Android 2.2 生成的项目,但后来我改变主意并切换到 4.1。但是项目中有这个 appcompat 依赖项。它有助于删除它。
  • @LeosLiterak 哇,2.2?那是旧版本的 Android。
【解决方案2】:

您确定您正在查找正确的 *.xml 文件吗?您似乎在布局 xmls 中寻找“showAsAction”,但它是菜单的参数。而是查看 .../menu/your_activity.xml

您正在处理的问题与使用小于 4.0 的目标和/或小于 14 的 API 有关。

所以,

a) 更改这些参数,

b) 将 showAsAction 的值从“never”更改为“ifRoom”。

【讨论】:

  • 嘿,刚刚看到你的答案,但我已经解决了这个问题,虽然你是对的,但我一直在看错误的 XML!不过感谢您的回答!
  • 我以为你已经知道了。我为那些可能正在处理同样事情但没有答案并且很难寻找答案的人回答。像我一样。
【解决方案3】:

如果您在 XML 中使用了资源标识符“ShowAsAction”,就会发生这种情况。 我猜这个功能只能从ver11开始。如果您尝试在较低的 API 版本上运行相同的程序,则会产生此错误。 解决方案 ->> 右键单击项目>属性> Android>构建目标>选择大于API 11的东西

【讨论】:

    【解决方案4】:

    您必须选择 4.0 或更高版本的 API 14,因为任何低于 4.0 的版本在其包中都不包含 showAsAction 属性

    【讨论】:

      【解决方案5】:

      正确的答案是使用

      android:showAsAction="ifRoom"
      

      而不是android在哪里

      xmlns:android="http://schemas.android.com/apk/res/android"
      

      【讨论】:

        【解决方案6】:

        安卓工作室

        如果您使用的是 ANDROID STUDIO......请使用此修复程序

        添加

        xmlns:compat="http://schemas.android.com/tools"

        在菜单标签中而不是

        xmlns:compat="http://schemas.android.com/apk/res-auto "

        菜单标签中。

        【讨论】:

          【解决方案7】:

          如果您将项目从 Android Studio 导入到 eclipse,只需添加:

          <?xml version="1.0" encoding="utf-8"?>
          

          在xml的头部,然后就全部修复了。

          【讨论】:

            猜你喜欢
            • 2011-07-12
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多