Add in ActionBar

0

I would like to know how to add an icon in the ActionBar of my application I have the following XML code

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

<!-- "Mark Favorite", should appear as action button if possible -->
<item
    android:id="@+id/action_favorite"
    android:icon="@drawable/ic_favorite_black_48dp"
    android:title="@string/action_favorite"
    app:showAsAction="ifRoom"/>

<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
      android:title="@string/action_settings"
      app:showAsAction="never"/>

   </menu>

But I do not have the "menu" folder, I'm not sure where to add it or how to do it.

    
asked by Franco Galuzzi 19.11.2016 в 12:02
source

1 answer

5

If with adding icons, you mean to incorporate actions in ActionBar , what you have to do is create within the res folder, a directory called < strong> menu , and there you enter the XML .

Then in the activity where you want to add this menu, add:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.nombredelxml, menu);
    return true;
}
    
answered by 19.11.2016 / 13:31
source