[英]error:no resource identifier found for attribute“showAsAction” in package android
[英]No resource identifier found for attribute 'showAsAction' in package 'android'
正如標題所示,我在至少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_不存在
當我忘記將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庫了。
您確定要查找正確的* .xml文件嗎? 你似乎在布局xmls中尋找“showAsAction”,但它是菜單的參數。 而不是... / menu / your_activity.xml
您正在處理的問題與使用小於4.0的目標和/或小於14的API相關聯。
所以,
a)改變那些參數,
b)將showAsAction的值從“never”更改為“ifRoom”。
如果您在XML中使用了resourceidentifier“ShowAsAction”,就會發生這種情況。 此功能僅在ver11中可用。 如果您嘗試在較低的API版本上運行相同的錯誤,則會生成此錯誤。 解決方案 - >>右鍵單擊項目>屬性> Android>構建目標>選擇大於API 11的內容
您必須選擇版本為4.0或更高版本的API 14,因為任何低於4.0的版本在其包中不包含showAsAction屬性
正確的答案是使用
android:showAsAction="ifRoom"
而不是android所在的地方
xmlns:android="http://schemas.android.com/apk/res/android"
ANDROID STUDIO
如果您使用的是ANDROID STUDIO ......請使用此修復程序
加
xmlns:compat="http://schemas.android.com/tools"
在菜單標簽而不是
xmlns:compat="http://schemas.android.com/apk/res-auto "
在菜單標簽中。
如果您將項目從Android Studio導入到eclipse,只需添加:
<?xml version="1.0" encoding="utf-8"?>
在xml的頭部,它將全部修復。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.