Unexpected namespace prefix with action bar

I am trying to implement an ActionBar through the support library, v7. Because I want to support an application for Android 2.1 (API level 7) and higher.

I read the following at http://developer.android.com/guide/topics/ui/actionbar.html : "Using XML attributes from the support library Please note that the showAsAction attribute above uses its own namespace defined in the tag. This is necessary when using any XML attributes defined by the support library because these attributes do not exist on the Android platform on older devices. Therefore, you should use your own namespace as a prefix for all attributes defined by the support library. "

<?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 shows me the error "Unexpected namespace prefix" myapp "found for tag element." I do not see what I am doing wrong.

+4
source share
1 answer

** You must add xmlns: tools as well as tools: context attribute for the menu tag **

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

Source: https://habr.com/ru/post/1502800/


All Articles