remove back/home button from action mode on long press in android

我的梦境 提交于 2019-12-11 04:40:18

问题


I have implemented contextual action mode on long press inside recycler view. For that i have called ActionModeCallback from creating action mode .

While creating action mode , back arrow is showing by default . Check below :

On click back arrow , action mode will close.

Now i want to hide or remove that default back button which is coming along with action mode in android .

Note : Already tried getActionBar().setDisplayHomeAsUpEnabled(false). but it's not working . Kindly help.

Edited :

Thanks Issues been resolved : After adding in style.xml

<item name="actionModeCloseDrawable">@color/colorPrimary</item>
    <item name="actionModeCloseButtonStyle">@style/Widget.AppCompat.ActionMode</item>

回答1:


Try this to completely remove it:

ActionBar actionBar = getActionBar();
if (actionBar != null) {
    actionBar.setHomeButtonEnabled(false);      
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false); 
}

Update

or try to using a custom theme

<style name="yourTheme" parent="theThemeYouUse">
    <item name="android:actionModeCloseDrawable">@drawable/yourBack</item>
</style>

and in the manifest:

<activity
        android:name="yourActivity"
        android:theme="@style/yourTheme"
  ...
/>



回答2:


Add below the item to your style

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
     ...
        <item name="actionModeCloseButtonStyle">@style/NoCloseButtonActionModeStyle</item>
    </style>
<style name="NoCloseButtonActionModeStyle">
        <item name="android:visibility">gone</item>
    </style>


来源:https://stackoverflow.com/questions/38138881/remove-back-home-button-from-action-mode-on-long-press-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!