0

i cannot seem to make the icons appear on the action bar on top of the activity at my project, i am using the right namespace with the right extend and everything should be running be smoothly, this is the xml for the menu items and i have added the line "xmlns:app="http://schemas.android.com/apk/res-auto"" and it still doesn't work

<?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_search"
    android:icon="@mipmap/ic_search_white_24dp"
    android:title="Search"
    android:showAsAction="ifRoom"/>
<item android:id="@+id/action_add"
    android:icon="@mipmap/ic_add_white_48dp"
    android:title="Add"
    android:showAsAction="ifRoom"/>

this is the java code for the menu inflater

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_actions, menu);
    return super.onCreateOptionsMenu(menu);
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Do you call the menu xml in your android activity? – makis.k Jan 02 '18 at 21:03
  • yes i just updated my question to add the activity part –  Jan 02 '18 at 21:21
  • Is the menu showing, in other words is the drop down menu showing? `ifRoom` is a bit finicky, if you want the icons to show try switching the `showAsAction` value to `always` – Chris Stillwell Jan 02 '18 at 21:24
  • yes when i click on the 3 dots the menu still works and everything is working perfectly fine, but the icons will never show, i even tried the value to always and still nothing –  Jan 02 '18 at 21:26
  • This might have to do with using mipmaps, try changing your icons to be in the drawable folder. See this question for more info: https://stackoverflow.com/questions/34867315/navigation-drawer-menu-icon-is-not-displayed-correctly – Chris Stillwell Jan 02 '18 at 21:30
  • i tried adding them to the drawable folder instead of the mipmap and still not working –  Jan 02 '18 at 21:35

2 Answers2

1

i found the solution to my problem. since i have been trying to use namespace

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

then i should use

app:showAsAction="ifRoom" 

instead of

android:showAsAction="ifRoom"
0

You have to inflate your menu using

getMenuInflater().inflate(R.menu.main, menu);

When you call onCreateOptionsMenu

Also try to add order attribute in your xml

makis.k
  • 432
  • 6
  • 23
  • i already did that, i will update my post to add the java code for it –  Jan 02 '18 at 21:14