Try as follows:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/testmeniitem"
android:title="Test Menu Item"
android:showAsAction="always"
app:showAsAction="always"
android:icon="@drawable/ic_launcher"
/>
</menu>
You need to put a custom namespace and set showAsAction
twice.
I know this is weird, but it has to be done that way to make sure the showAsAction
works on all APIs and with all compatibility libraries.
From the ActionBar buttons documentation page:
If your app is using the Support Library for compatibility on versions as low as Android 2.1, the showAsAction attribute is not available from the android: namespace. Instead this attribute is provided by the Support Library and you must define your own XML namespace and use that namespace as the attribute prefix. (A custom XML namespace should be based on your app name, but it can be any name you want and is only accessible within the scope of the file in which you declare it.)