在'android'包中找不到属性'showAsAction'的资源标识符

Mok*_*oko 12 java android android-xml android-menu

正如标题所示,我在至少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>
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)

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

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

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

Igo*_*sky 12

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

dependencies {
  compile 'com.android.support:appcompat-v7:+'
}
Run Code Online (Sandbox Code Playgroud)

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

xmlns:app="http://schemas.android.com/apk/res-auto"
Run Code Online (Sandbox Code Playgroud)

app:showAsAction="never"
Run Code Online (Sandbox Code Playgroud)

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

  • 这里说它必须使用showAction的自定义命名空间http://developer.android.com/guide/topics/ui/actionbar.html (3认同)

lew*_*tor 8

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

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

所以,

a)改变那些参数,

b)将showAsAction的值从"never"更改为"ifRoom".

  • 我以为你已经有了这个.我回答那些可能处理相同事情而没有答案并且很难找到它的人.像我这样的. (2认同)