How to Customize the Contextual Action Bar Using Appcompat in Material Design

how to Customize the Contextual Action Bar using appCompat in material design

You can change the ActionMode background through attribute actionModeStyle:

<style name="AppTheme.Base" parent="Theme.AppCompat.Light">
....
....
<item name="actionModeStyle">@style/LStyled.ActionMode</item>
</style>

<style name="LStyled.ActionMode" parent="@style/Widget.AppCompat.ActionMode">
<item name="background">@color/color_action_mode_bg</item>
</style>

You will of course need to define a color named color_action_mode_bg:

<color name="color_action_mode_bg">#009688</color>

There are other things you can change as well. Example:

<item name="titleTextStyle">...</item>
<item name="subtitleTextStyle">...</item>
<item name="height">...</item>

To change text color of SAVE and SAVETO, add the following to AppTheme.Base:

<item name="actionMenuTextColor">@color/color_action_mode_text</item>

Toolbar and Contextual ActionBar with AppCompat-v7

Update:

Solution: use the windowActionModeOverlay property. Set this in your theme:

<item name="windowActionModeOverlay">true</item>

and the actionmode will be shown over the action bar instead of pushing it down. (If you're not using the latest AppCompat then you need to add the "android:" prefix to the property). It basically lets AppCompat know that you have a toolbar located in the top of the screen and that it should draw the ActionMode on top of it.



Old answer/workaround:

I ran into the same problem. No matter what theme I set, it always pushes down the Toolbar I set as ActionBar. I tried with and without the support library, but it didn't matter.

Unfortunately I was not able to fix it so I have built a workaround instead. In my ActionModeCallback's onCreateActionMode I hide the action bar:

actionBarToolbar.setVisibility(View.GONE);

and in onDestroyActionModeI show it again:

actionBarToolbar.setVisibility(View.VISIBLE);

The hiding/showing happens so quickly it is not noticeable on my test devices. There is of course a downside: although the enter-animation still works, the exit-animation of the contextual action bar gets lost because the Toolbar immediately pops over it. But until we come across a better solution I guess we are stuck with this.


(My Activity is actually extending a custom BaseActivity class which has a method called getActionBarToolbar(), taken from the Google I/O 2014 app source code, so I can easily get fetch the Toolbar:

BaseActivity activity = (BaseActivity) getActivity();
activity.getActionBarToolbar().setVisibility(View.GONE);

Too bad the I/O app does not use the contextual action bar.)

Styling the contextual action bar?

Try adding this to your style in your styles.xml and use any custom color you would like.

<item name="android:actionModeBackground">@android:color/holo_orange_light</item>

You can also change the drawables for each icon using similar code.

android:actionModeCloseDrawable
android:actionModeCopyDrawable
android:actionModeCutDrawable
android:actionModePasteDrawable
android:actionModeSelectAllDrawable

Credit to the tutorial here - http://www.codercowboy.com/2013/07/05/styling-the-contextual-action-bar-actionmode-divider-or-splitter-for-android/
for changing the contextual action bar icons. Which told me that starting with actionMode changes the contextual action bar attributes

Contextual Action Bar using AppCompat

Why do you call listView.clearChoices() every time the item checked state changes? I don't see the whole code but it seems like you clear all of the checks and then just check that item.

Contextual Actionbar styles

I posted a comment to my own question, and this is actually a bug in the version of android I was using (Probably an early version of 4.0)

This is the bug described: http://code.google.com/p/android/issues/detail?id=26008

Material Design - AppCompat toolbar without showing shadow

Those two are completely different shadows. The vertical one is that of DrawerLayout. It's supposed to be showing beside expanded drawer. The horizontal one is part of windowContentOverlay on APIs below LOLLIPOP (on LOLLIPOP it's @null).

When you work with Toolbar widget the toolbar isn't part of window decor anymore so the shadow starts at the top of the window over the toolbar instead of below it (so you want the windowContentOverlay to be @null). Additionally you need to add an extra empty View below the toolbar pre-LOLLIPOP with its background set to a vertical shadow drawable (8dp tall gradient from #20000000 to #00000000 works best). On LOLLIPOP you can set 8dp elevation on the toolbar instead.

Note: Use the same gradient but horizontal as the drawer shadow for best results.



Related Topics



Leave a reply



Submit