1

i tried some sugestions here but no one worked,

this is the problem, the arrow indicate where i want them

the action bar is displaying just 2 icons enter image description here

and the other are in the 3 dots menu

enter image description here

My custom_menu.xml

<item
    android:id="@+id/btnBold"
    android:icon="@drawable/text_bold"
    app:showAsAction="always"
    android:onClick="onContextualMenuItemClicked"
    android:title="Teste1">
</item>

    <item
        android:id="@+id/btnItalic"
        android:icon="@drawable/text_italic"
        app:showAsAction="always"
        android:onClick="onContextualMenuItemClicked"
        android:title="teste2">
    </item>

    <item
        android:id="@+id/btnUnderline"
        android:icon="@drawable/text_underline"
        app:showAsAction="always"
        android:onClick="onContextualMenuItemClicked"
        android:title="teste3">
    </item>

    <item
        android:id="@+id/btnStrike"
        android:icon="@drawable/text_strike"
        app:showAsAction="always"
        android:onClick="onContextualMenuItemClicked"
        android:title="teste2">
    </item>

    <item
        android:id="@+id/btnForeground"
        android:icon="@drawable/text_foreground"
        app:showAsAction="always"
        android:onClick="onContextualMenuItemClicked"
        android:title="teste2">
    </item>

    <item
        android:id="@+id/btnBackground"
        android:icon="@drawable/text_background"
        app:showAsAction="always"
        android:onClick="onContextualMenuItemClicked"
        android:title="teste2">
    </item>

</menu>

and the code at the MainActivity

private ActionMode mActionMode = null;

    @Override
    public void onActionModeStarted(ActionMode mode) {
        if (mActionMode == null) {
            mActionMode = mode;
            Menu menu = mode.getMenu();
            // Remove the default menu items (select all, copy, paste, search)
            menu.clear();

            // If you want to keep any of the defaults,
            // remove the items you don't want individually:
            // menu.removeItem(android.R.id.[id_of_item_to_remove])

            // Inflate your own menu items
            mode.getMenuInflater().inflate(R.menu.my_custom_menu, menu);
        }

        super.onActionModeStarted(mode);
    }

    // This method is what you should set as your item's onClick
    // <item android:onClick="onContextualMenuItemClicked" />
    public void onContextualMenuItemClicked(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.btnBold:
                // do some stuff
                break;
            case R.id.btnItalic:
                // do some different stuff
                break;
            default:
                // ...
                break;
        }

        // This will likely always be true, but check it anyway, just in case
        if (mActionMode != null) {
            //mActionMode.finish();
        }
    }

    @Override
    public void onActionModeFinished(ActionMode mode) {
        mActionMode = null;
        super.onActionModeFinished(mode);
    }
user2582318
  • 1,607
  • 5
  • 29
  • 47
  • 2
    and whats going to happen when they dont all fit on the screen? – tyczj Jun 29 '15 at 14:26
  • in this case its ok to shrink, but it has a lot of space in the left, why hide? – user2582318 Jun 29 '15 at 14:28
  • 2
    the actionbar does not shrink items, what you want to do is not going to work – tyczj Jun 29 '15 at 14:29
  • shrink was just way to say, so i have to change my approach =/, you know how to make a popup dialog appaer above the selected item? i mean, like when you have a EditText/TExtview and select text, a kind of bublle appear, maybe this can fit my needs (sorry this question here) – user2582318 Jun 29 '15 at 14:31
  • Hi @user2582318, did you figure a way out? – Luccas Sep 15 '15 at 03:39
  • @Luccas, its impossible, you cant show all items, i changed it to a normal relativelayout and i show it when i need! You can create a toolbar and add a lot of buttons and show, but in the actionbar you cant, it automatically reduce and display one or two, you can just choose which ONE you want to display first – user2582318 Sep 15 '15 at 11:32

1 Answers1

0

Have you already tried the answer of this question?

Android 4.3 menu item showAsAction="always" ignored

Basically, what he said was that you must be missing the namespace. The proper way to do this would be:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:[yourapp]="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/menu_add_size"
    android:title="@string/menu_add_item"
    android:orderInCategory="10"
    [yourapp]:showAsAction="always"
    android:icon="@android:drawable/ic_menu_add" />
</menu>

I had this problem and solved it by changing the specific namespace. Hope you can fix by doing this too.

Community
  • 1
  • 1
cristianorbs
  • 670
  • 3
  • 9
  • 16