3

I have CAB menu in my application. I have a requirement to change the text on "DONE" button to "ADD". How can I do that?

I am able to see the design elements.But not for my requirement.

<item name="android:actionModeCloseDrawable"></item>
<item name="android:actionModeCutDrawable"></item>
<item name="android:actionModeCopyDrawable"></item>
<item name="android:actionModePasteDrawable"></item>
<item name="android:actionModeSelectAllDrawable"></item>
<item name="android:actionModeBackground"></item>
<item name="android:actionModeCloseButtonStyle"></item>
intrepidkarthi
  • 3,104
  • 8
  • 42
  • 75
  • 2
    IMHO, "Add" does not make sense when dismissing an action mode. An action mode, on its own, should *not* be changing the state of anything, just by being displayed. It simply brings up additional operations designed to be operated on something (e.g., checked-off items in a list). – CommonsWare Jan 11 '13 at 18:42
  • I am adding some items to my list when the action bar is dismissed. So it will be good if the text is "ADD" instead of "DONE". Is it wrong in doing any operation while dismissing the action mode? – intrepidkarthi Jan 11 '13 at 19:30
  • 1
    "I am adding some items to my list when the action bar is dismissed" -- IMHO, that is not a good idea. An action mode is nothing more than a better-looking context menu. Displaying a menu, and not selecting anything from it, should not be a destructive act. Similarly, displaying an action mode, and not doing anything with it, should not be a destructive act. Again, this is all my opinion. – CommonsWare Jan 11 '13 at 19:41
  • Fine. Thanks for the suggestion. I will do the operation by adding another button on the CAB menu. – intrepidkarthi Jan 11 '13 at 19:51
  • I suppose this question hasn't really been answered though - I have a similar case, where I need to change the "Done" text to "Cancel" - the user is cancelling the action, indicating that he does not want to change anything (pressing the back button has the same effect). Any pointers? – jrharshath Feb 21 '13 at 17:10
  • No luck for me till now! – intrepidkarthi Feb 25 '13 at 07:37
  • Please look into this, it may help you. http://stackoverflow.com/questions/14964939/remove-done-button-of-actionmode/17144854#17144854 – paibhavesh Jun 17 '13 at 10:06

1 Answers1

-3

You define this in an xml files like other menus. Then reference that in the callback like so

private final class ModeCallback implements ActionMode.Callback {

    @Override
    public boolean onCreateActionMode(ActionMode mode, Menu menu) {
        MenuInflater inflater = Activity.getSupportMenuInflater();
        inflater.inflate(R.menu.contexual_menu, menu);
        return true;
    }

    @Override
    public boolean onPrepareActionMode(ActionMode mode, Menu menu) {

        return false;
    }

    @Override
    public void onDestroyActionMode(ActionMode mode) {
        //Destroy something
    }

    @Override
    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
        Toast.makeText(Activity.this, "Well done you made an custom CAB", Toast.LENGTH_SHORT).show();

    }
};

Make sure you start the actionMode like this

startActionMode(new ModeCallback());
jiduvah
  • 5,108
  • 6
  • 39
  • 55