android - 带有操作栏的意外 namespace 前缀

标签 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 向我显示错误“为标记项找到意外的 namespace 前缀“myapp””。我不明白,我做错了什么。

最佳答案

**您必须为菜单标签添加 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 **

关于android - 带有操作栏的意外 namespace 前缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18871947/

相关文章:

java - Android 更新通知并检测它何时不再存在

xaml - XAML 命名空间的最佳命名约定是什么?

Android ActionBar 兼容溢出菜单未在 sdk 10 上显示

android - 使用 Intent.ACTION_PICK 读取电话号码和地址

android - 如何在 Android Studio 中使用 onMarkerClick 打开一个新 Activity

android - 允许用户选择 SD 卡上的文件夹

ruby-on-rails - Rails 3 管理部分关于继承和命名空间的设计问题

clojure - 为什么 Clojure 在创建新的命名空间后不提供标准库?

android - 如何去除透明 ActionBar 的标题背景?

android - ActionBarActivity 在 Phone 上捕获错误