2016-11-11 70 views
0

因此,我不想在某些情况下关闭动作模式。所以试着做以下上下文当按下实体后退按钮时,动作栏(动作模式)总是被破坏

@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); 
} 

但仍始终关闭CAB每次我按后退按钮的时间。 可能是什么原因?

回答

0

添加这在styles.xml文件

<!-- 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> 
+0

,也看看这个(http://www.androhub.com/android-contextual-action-mode-over-toolbar/)可帮你... –

相关问题