2012-12-03 82 views
12

作为标题提示,我得到至少3个XML布局文件中的错误,但是,我没有看到任何attritube“showsAsAction”这些XML文件的,我错过了什么或者我只是盲目的?这里是XML文件中的问题:找不到属性'showAsAction'的资源标识符'android'

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

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

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

错误产生最终的归档文件:java.io.FileNotFoundException:C:\用户\\的文档\的Android \ Registro德ASISTENCIA \ BIN \资源.ap_不存在

+1

尝试清理您的项目 –

+0

@BinoyBabu感谢您的回答。尝试,但不幸的是没有工作。事实上,我不知道为什么,但每次我尝试清理项目时,R.java文件都会被删除,似乎不会再自动生成。幸运的是我有一个项目文件夹的备份。任何想法可能是什么? – Moko

+2

可能是损坏的ADT插件或Android SDK。尝试重新安装两者。 –

回答

8

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

你是在处理与利用的目标低于4.0和/或API小于14

所以连接的问题,

一)更改这些参数,

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

+0

嘿,刚才看到你的答案,但我已经解决了这个问题,虽然你是对的,但我一直在看错误的XML! 感谢您的答案,但! – Moko

+2

我以为你已经得到了这个。我回答了那些可能会遇到同样问题但没有答案并且很难找到答案的人。像我这样的。 – lewildcapacitor

3

如果您在XML中使用了resourceidentifier“ShowAsAction”,就会发生这种情况。 此功能只能从ver11我猜。如果您试图在较低的API版本上运行此错误,则会产生此错误。 解决方案 - >> 右键单击项目>属性>安卓>构建目标>选择的东西比API大于11

1

正确的答案是使用

android:showAsAction="ifRoom" 

,而不是在那里Android是

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

为什么android:showAsAction =“ifRoom”不好? –

2

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

12

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

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

而这是因为我在我的菜单中有以下内容。XML:

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

app:showAsAction="never" 

当我删除了的xmlns:应用命名空间,只用于android:showAsAction="never",我并不需要的程序兼容性-V7库了。

+3

这里说它必须使用showAction的自定义命名空间http://developer.android.com/guide/topics/ui/actionbar.html – likejiujitsu

+0

是的,我想这对旧设备是有意义的。 –

+0

我把它与对面的方式 - Studio生成的Android 2.2项目,但我后来改变了主意,并切换到4.1。但是这个appcompat依赖项目。它帮助删除它。 –

1

ANDROID STUDIO

如果您正在使用ANDROID STUDIO ......用这个解决

在菜单标签,而不是

添加

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

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

菜单标签。

-1

如果要导入Android工作室项目偏食,只需添加:

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

在XML的头部,然后将全部解决。

相关问题