我正在尝试通过支持库 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/