0

well the problem is that my icon of my option add item on the action bar does not appear(it has space for show the icon but it does not). my option just appear on the dropdown menu (the 3 points XD) thanks you. here is my code xml then my code java:

<?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/menuAddItem"
 android:title="Add Item"
 android:icon="@android:drawable/ic_menu_add"
 app:showAsAction="ifRoom"
/>

</menu>

java:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.clear();
MenuInflater infladorMenu = new MenuInflater(this);
infladorMenu.inflate(R.menu.menu,menu);
return true;

 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {

  switch (item.getItemId()){
    case R.id.menuAddItem:
        this.listaDatos.add("Dato Añadido");
        this.adaptador.notifyDataSetChanged();
        break;
  }

  return super.onOptionsItemSelected(item);
}

As you can see the icon does not appear but the actionbar has space

As you can see the icon does not appear but the actionbar has space, my option is just showed in the dropdown menu. thank you for your help.

  • Just change the property `app:showAsAction="ifRoom"` to `app:showAsAction="always"` and/or `android:showAsAction="always"` take a look at this post :: https://stackoverflow.com/questions/23230939/items-not-showing-in-the-actionbar-with-showasaction-always – Barns Nov 08 '18 at 21:41
  • This might also help :: https://stackoverflow.com/questions/26377305/item-with-appshowasaction-not-showing – Barns Nov 08 '18 at 21:48
  • Possible duplicate of [Item with app:showAsAction not showing](https://stackoverflow.com/questions/26377305/item-with-appshowasaction-not-showing) – Barns Nov 08 '18 at 21:49
  • thanks it works doing android:showAsAction="always", but i would like to know why does not work with app:showAsAction="always". thanks for your help. – David Garcia Nov 08 '18 at 22:09
  • This might have to do with the class from which your activity is being extended. My activities generally extend from `android.support.v7.app.AppCompatActivity` and I have had success with `app:showAsAction="always"`. Check to see which class your `Activity` extends. – Barns Nov 08 '18 at 22:13
  • @Barns my Activity(called GridActivity) extends from android.support.v7.app.AppCompatActivity but when i use app:showAsAction="always" it does not work. – David Garcia Nov 08 '18 at 23:26

0 Answers0