0

So, I don't want to close Action mode on certain condition. so tried to do following

@Override
public boolean dispatchKeyEvent(KeyEvent event) {

if (my condition) {
    if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
        return true; // consuming back event here. and yes it gets called on backpress meaning event gets consumed successfully here
    }   
}
    return super.dispatchKeyEvent(event);
}

but still it always closes CAB every time i press back button. what could be the reason ?

Apsaliya
  • 136
  • 3
  • 10

1 Answers1

0

Add this in your styles.xml file

<!--  It should be true otherwise action mode will not overlay toolbar -->
        <item name="windowActionModeOverlay">true</item>

        <!--  For Custom Action Mode Background Color/Drawable -->
        <item name="actionModeBackground">@color/colorAccent</item>
Nikul Rao
  • 83
  • 8
  • and also check out this (http://www.androhub.com/android-contextual-action-mode-over-toolbar/) may help you... – Nikul Rao Aug 16 '17 at 06:45