-3

i don't know why adding an <item> to an Android action bar adds it to the menu instead.

this is the content of the menu xml file:

<item
    android:id="@+id/showMenu"
    android:title="test"
    android:icon="@drawable/ic_launcher"
    android:showAsAction="always"
    />

The showAsAction line is undefined in red with a message : "should use app:showAsAction with the AppCompat library..."

The Android documentation says '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 ... ' and to use yourApp:showAsAction to support versions 2.1 to 3.0

But the minimum I support is 4.2 (SDK 18)

So why am I getting this message and how to solve this ?

enter image description here

KNS
  • 101
  • 1
  • 5

1 Answers1

0

Try using

app:showAsAction="always"

in the tag and include

xmlns:app="http://schemas.android.com/apk/res-auto"

in the tag

something like

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/showMenu"
        android:title="test"
        android:icon="@drawable/ic_launcher"
        app:showAsAction="always"
    />
 </menu>
Renan Ferreira
  • 2,122
  • 3
  • 21
  • 30