Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Menu items should specify a title

Tags:

android

xml

I've got this problem but the thing is that I do have a title

 <menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:android="http://schemas.android.com/apk/res-auto"
  xmlns:android="http://schemas.android.com/tools">
  <!-- Search, should appear as action button -->
  <item
    android:title="@string/action_search"
    android:id="@+id/action_search"
    android:icon="@drawable/ic_action_search"
    android:showAsAction="ifRoom"  />
  <item
    android:title="@string/action_settings"
    android:id="@+id/action_settings"
    android:showAsAction="never" />
  </menu>

in the strings xml file i did the strings, the program even switches the action_search and action_settings with its string - search and settings.

like image 534
user3703454 Avatar asked Jan 16 '15 08:01

user3703454


3 Answers

Just a wrong XML namespace! Try with:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
</menu>

And as G.T. suggested you should consider using appcompat on the showAsAction property (only needed if you want to support API < 11):

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/item1"
        android:icon="@drawable/ic_launcher"
        app:showAsAction="ifRoom|withText"
        android:title="@string/Add_New" />
</menu>

Note:

The appcompat library is compatible with some old Android versions (API 7+) that can't handle the showAsAction property because they don't have the ActionBar (API < 11).

like image 67
Fakher Avatar answered Nov 15 '22 17:11

Fakher


can you remove those things xmlns:android="schemas.android.com/apk/res-auto"; xmlns:android="schemas.android.com/tools";

Also try to follow Goolge dev examples here http://developer.android.com/guide/topics/ui/menus.html

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/new_game"
          android:icon="@drawable/ic_new_game"
          android:title="@string/new_game"
          android:showAsAction="ifRoom"/>
    <item android:id="@+id/help"
          android:icon="@drawable/ic_help"
          android:title="@string/help" />
</menu>
like image 21
arthur_gg Avatar answered Nov 15 '22 18:11

arthur_gg


It actually need a namespace to identify the process.

<?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/action_shuffle"
    android:icon="@drawable/android_music_player_rand"
    android:orderInCategory="1"
    app:showAsAction="always"
    android:title="Shuffle"
    android:onClick="shuffle"/>
<item
    android:id="@+id/action_end"
    android:icon="@drawable/end"
    android:orderInCategory="2"
    app:showAsAction="always"
    android:title="End"
    android:onClick="end"/>
</menu>
like image 29
Cms Avatar answered Nov 15 '22 17:11

Cms