【问题标题】:unexpected namespace prefix with actionbar带有操作栏的意外命名空间前缀
【发布时间】:2013-09-23 04:42:18
【问题描述】:

我正在尝试通过支持库 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 向我显示错误“为标签项找到意外的命名空间前缀“myapp””。我不明白,我做错了什么。

【问题讨论】:

  • 我找到了类似的解决方案。如果我清理我的项目,错误就会消失,我可以启动我的应用程序。但是,当我在 xml 中更改完全不同的内容并保存时,错误再次出现,必须再次清理。

标签: android namespaces android-actionbar-compat


【解决方案1】:

**你必须为菜单标签添加 xmlns:tools 和 tools:context 属性**

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

【讨论】:

    猜你喜欢
    • 2016-04-05
    • 2013-05-06
    • 2013-05-03
    • 2011-05-09
    • 2015-06-05
    • 1970-01-01
    • 1970-01-01
    • 2021-07-27
    • 1970-01-01
    相关资源
    最近更新 更多