0

I have a contextual action bar with three menu items. There is definitely room on the CAB, but only one item shows and the other two are forced into the oveflow menu. If I use android:showAsAction="always" in all three menu items,nothing happens. they still appear on the overflow. Am using toolbar as the actionbar in my activity which extends AppCompatActivity.

When CAB is shown

CAB ACTIVATED

When overflow is clicked

enter image description here

My menu layout

    <?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/delete_item"
          app:showAsAction="always"
          android:actionLayout="@layout/delete_button"
          android:title="@string/delete">

    </item>

    <item android:id = "@+id/copy_item"
        android:title="@string/copy"
       android:actionLayout="@layout/copy_button"
          app:showAsAction="always">

        </item>

    <item android:id = "@+id/forward"
        android:title="@string/forward"
        android:actionLayout="@layout/forward_button"
          app:showAsAction="always">

    </item>

</menu>

my custom layout for delete menu item (content is the same for all custom layouts of the 3 menu items)

 <?xml version="1.0" encoding="utf-8"?>
<Button
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableTop="@drawable/delete"
    android:text="@string/delete"
    android:id="@+id/menuDelete"
    android:background="@android:color/transparent"
    android:layout_gravity="left"
    android:textSize="14sp"
    android:textColor="@color/blue"
    />

my activity theme

<style name="myTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionModeOverlay">true</item>
        <item name="android:popupBackground">#55acee</item>
        <item name="android:actionMenuTextColor">@android:color/white</item>
        <item name="android:textColorSecondary">@android:color/white</item>
    </style>

Why are my 2 menu items being taken to overflow even when there is space in CAB?

Edijae Crusar
  • 3,473
  • 3
  • 37
  • 74
  • may be your `actionLayout` passed to menu is taking more space than expected because `showAsAction` options `always` and `ifRoom` works similar only more preference is given to `always`. – himanshu1496 Aug 09 '16 at 13:46
  • @himanshu1496 so you are suggesting that i should remove `showAsAction` option. – Edijae Crusar Aug 09 '16 at 13:48
  • removing also won't help as per your requirement, you can probably check if the layout you have passed is taking more space, may be if you can control that other option might become visible. – himanshu1496 Aug 09 '16 at 13:50
  • @himanshu1496 as you can see in my question, my layout width and height are all set to `wrap_content` – Edijae Crusar Aug 09 '16 at 13:52
  • that's what dude, it's a button it might have some padding, try giving fixed height and width say `48dp` and see what happens. – himanshu1496 Aug 09 '16 at 13:57
  • @himanshu1496 even when i remove the custom layout, and set icons which are very small, no changes happens. the other two items are still pushed to overflow – Edijae Crusar Aug 10 '16 at 06:29
  • okay then it must be something else. – himanshu1496 Aug 10 '16 at 06:34

0 Answers0