linux_user36
linux_user36

Reputation: 213

ActionMode with same theme as Toolbar in Android

In Android, is there any way to give an ActionMode the same appearance as the normal Toolbar? Currently my ActionMode looks different to the Toolbar in that the background is slightly brighter (at least using Theme.AppCompat.NoActionBar), the MenuItems are fully black/white (depending on the theme) instead of colorControlNormal (which I set them to) and most annoyingly, there is an underline under the ActionMode that I can't seem to get rid of. Instead, I'm trying to make the ActionMode indistinguishable from the Toolbar.

The Toolbar (also what the ActionMode is meant to look like): Toolbar

What the ActionMode currently looks like: ActionMode

Any help would be highly appreciated!

Upvotes: 0

Views: 379

Answers (1)

Mayur Gajra
Mayur Gajra

Reputation: 9073

  1. For changing the background color of ActionMode & Remove the bottom line. You can use actionModeStyle where you can set background to your desired color.
  2. For changing the icon color you can set colorControlNormal inside the actionBarTheme.

So your theme would look like this:

<style name="Theme.AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

        <!--add this-->
        <item name="actionModeStyle">@style/ActionModeStyle</item>
        <item name="actionBarTheme">@style/MyActionBarTheme</item>

    </style>

    <style name="MyActionBarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
        //replace with your own desired color
        <item name="colorControlNormal">#a00</item>
    </style>

    <style name="ActionModeStyle" parent="@style/Widget.AppCompat.ActionMode">
        //replace with your own desired color
        <item name="background">@color/colorPrimary</item>
        <item name="titleTextStyle">@style/ActionModeTitleTextStyle</item>
    </style>

    <style name="ActionModeTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionMode.Title">
        //replace with your own desired color
        <item name="android:textColor">#a00</item>
    </style>

Upvotes: 2

Related Questions