user2021938
user2021938

Reputation: 145

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

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 :

enter image description here

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>

Upvotes: 2

Views: 2559

Answers (2)

Robotic Vn
Robotic Vn

Reputation: 577

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>

Upvotes: 0

Erik Minarini
Erik Minarini

Reputation: 4845

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"
  ...
/>

Upvotes: 2

Related Questions