Trying to use the Material Icons in the menu of the letter game -

a game

Download PNG files you like -

icons

And added them to both menus-file of the mobile application -

menu_main.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" > <item android:id="@+id/action_settings" android:orderInCategory="100" android:icon="@drawable/ic_settings_black_24dp" android:title="@string/action_settings"/> </menu> 

menu_game.xml:

 <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" > <item android:id="@+id/action_swap" android:orderInCategory="20" android:icon="@drawable/ic_swap_vert_black_24dp" android:title="@string/action_swap"/> <item android:id="@+id/action_shuffle" android:orderInCategory="40" android:showAsAction="always" android:icon="@drawable/ic_swap_horiz_black_24dp" android:title="@string/action_shuffle"/> <item android:id="@+id/action_recall" android:orderInCategory="60" android:icon="@drawable/ic_undo_black_24dp" android:title="@string/action_recall"/> <item android:id="@+id/action_turn" android:orderInCategory="80" android:icon="@drawable/ic_done_black_24dp" android:title="@string/action_turn"/> </menu> 

But alas, “the magic lantern does not light up” and the icons are still not visible.

Adding android:showAsAction="always" or android:showAsAction="ifRoom" problem is also not treated.

I ask for help with advice given the important conditions for me - my game uses AppCompatActivity with fragments and minSdkVersion=“8” .

I also ask you not to offer outdated libraries like ActionBarSherlock , but on the contrary - to recommend a modern (for 2015) solution to the problem of showing icons instead of text in the menu and Action Bar.

    3 answers 3

    Replace android:showAsAction with app:showAsAction , xmlns: app you have already registered. When using AppCompat, you need to use a different namespace for showAsAction , actionViewClass , actionProviderClass attributes , since they were not in older versions of android (prior to version 3.0).

    This is described in the action bar manual.

      Use the Toolbar (if you don't do this) instead of the ActionBar He has more opportunities, you can draw the buttons yourself inside and use them. Toolbar is prescribed in the main layout file Activity. And it is not necessary to write menu items in the menu_game.xml file. Example:

      Code

      • Good advice, I'll go to the Toolbar - thanks (I clicked +1) - Alexander Farber

      Just yesterday there was a similar problem. Try something like this: You need to add to the menu tag

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

      and item

       com.example.app:showAsAction="always" 

      Instead of com.example.app insert your own.