带有操作栏的意外命名空间前缀

时间:2013-09-18 12:12:54

标签: android namespaces android-actionbar-compat

我正在尝试通过支持库v7实现ActionBar。因为我想支持适用于Android 2.1(API级别7)及更高版本的应用程序。

我在http://developer.android.com/guide/topics/ui/actionbar.html中读到以下内容:“使用支持库中的XML属性请注意,上面的showAsAction属性使用标记中定义的自定义命名空间。当使用支持库定义的任何XML属性时,这是必需的,因为旧设备上的Android框架中不存在这些属性。因此,您必须使用自己的命名空间作为支持库定义的所有属性的前缀。“

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:myapp="http://schemas.android.com/apk/res-auto"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item        
        android:id="@+id/refresh"
        android:icon="@drawable/ic_navigation_refresh"
        android:title="@string/refresh"
        myapp:showAsAction="always"/> 
    <item
        android:id="@+id/settings"
        android:title="@string/settings"
        myapp:showAsAction="always"/>

    <item
        android:id="@+id/logout"
        android:title="@string/logout"
        myapp:showAsAction="always"/>
</menu>  

Eclipse向我显示错误“Unexpected namespace prefix”myapp“found for tag item”。我没有看到,我做错了什么。

1 个答案:

答案 0 :(得分:0)

**您必须添加xmlns:工具以及工具:菜单标签的上下文属性**

    <menu xmlns:myapp="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context="com.companyname.myapp.MainActivity">

    **Here in xmlns:context you have replace companyname and MainActivity as per need **

    **Other wise you have to clean and rebuild your project because IDE shows such error when they didn't got perfect project workspace OR module **
相关问题