Contextual Actionbar styles
Asked Answered
S

4

23

I'm looking for style information on the Contextual Action bar (CAB). I just need to change the colour of the text in fact..

Result of contextual actionbar

As you can see from the above, this is using the standard Theme.Holo.Light.DarkActionBar theme, so I just need to set the text colour to white!

Can anyone point me in the right direction?

Stemma answered 26/4, 2012 at 17:19 Comment(1)
Looks like this is a bug: code.google.com/p/android/issues/detail?id=26008Stemma
S
4

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

Stemma answered 31/1, 2013 at 21:20 Comment(0)
B
51

To change the color/etc of the text in a contextual action bar:

public boolean onCreateActionMode(ActionMode mode, Menu menu) {
  //mode.setTitle("Contextual Action Bar"); (replace this call)
  TextView tv= (TextView)getLayoutInflater().inflate(R.layout.contextual_title, null);
  tv.setText("Contextual Action Bar");
  mode.setCustomView(tv);

where layout/contextual_title.xml contains a single TextView with your desired color/size/style etc

In fact, almost everything in a contextual action bar can be styled. The only problem is that searching for the word 'contextual' leads nowhere useful. The relevant styling features are all called "actionMode...". Here are some I used (defined in my Theme.)

<item name="android:actionModeCloseDrawable">@drawable/check</item>
<item name="android:actionModeCutDrawable">@drawable/ic_menu_cut_holo_dark</item>
<item name="android:actionModeCopyDrawable">@drawable/ic_menu_copy_holo_dark</item>
<item name="android:actionModePasteDrawable">@drawable/ic_menu_paste_holo_dark</item>
<item name="android:actionModeSelectAllDrawable">@drawable/ic_menu_selectall_holo_dark</item>
<item name="android:actionModeBackground">@drawable/contextual</item>
<item name="android:actionModeCloseButtonStyle">@style/MyCloseButton</item>

<!-- these change the press backgrounds for the vanilla actionBar and for search -->
<item name="android:windowContentOverlay">@null</item>
<item name="android:selectableItemBackground">@drawable/bar_selector</item>
<item name="android:actionBarItemBackground">@drawable/bar_selector</item>      

<!-- these were defined in platform/.../data/res/values/... but Eclipse didn't recognize them -->
<!--? item name="android:actionModeShareDrawable">@drawable/icon</item -->
<!--? item name="android:actionModeFindDrawable">@drawable/icon</item -->
<!--? item name="android:actionModeWebSearchDrawable">@drawable/icon</item -->
<!-- item name="android:actionModeBackground">@drawable/red</item -->

<!-- and finally -->
<style name="MyCloseButton" parent="android:style/Widget.ActionButton.CloseMode">
    <item name="android:background">@drawable/bar_selector</item>
</style>

You can easily set your own text-editing cut/paste/copy/selectall icons, the bar background, and the icon background that changes color when you press the icons(bar_selector above). The icons are ImageViews, not buttons, and the edit id's (and the pressable background) are attached to the ImageView's parent (one parent per view) which is an 'internal' type.

It's never clear what goes where in the styles--I found where selectableItemBackground was in the platform Themes.xml, and copied and modified the drawable pointed at.

Boredom answered 30/6, 2012 at 19:43 Comment(5)
one thing that's not covered here- how to change the text color of the close button (not the title). on many of my devices, it still shows as dark even though i've set the style of the close mode button to be regular holo. i've even tried setting the text color in the close mode style.Boehmite
Can u please explain more in details how do u change the background of the CAB, because when i put the item="android:actionModeBackground" in my style for my actionbar, nothing happens for me :(Test
I'm a bit surprised this answer has had so many upvotes because it doesn't answer the question. The problem here is that it's a bug.Stemma
The answer is useful that is why it is up voted. The checkmark signifies acceptance to the question.Byrom
How can you change the background of the CAB's overflow menu?Test
S
4

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

Stemma answered 31/1, 2013 at 21:20 Comment(0)
A
0

If you're starting the contextual action mode manually, you can call setTheme() with a new theme before launching it (maybe Theme.AppCompat.Light.DarkActionBar if you're trying to avoid the black-on-black text issue). This will not affect the theme of the current activity if you've already set the activity's content view.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.my_activity_layout);

    // these lines can occur anywhere so long as you've already 
    // called "setContentView()" on the activity. The theme
    // you set here will apply to the action mode, but not to 
    // the activity.
    setTheme(R.style.Theme_AppCompat_Light_DarkActionBar);
    startSupportActionMode(myActionModeCallback);

}
Albarran answered 11/12, 2013 at 17:9 Comment(0)
A
0

it works now, but you have to enter it in values/styles.xml (not values-v#/styles.xml) and enter it in the general (non-API specific tag)

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:actionModeCloseDrawable">@drawable/ic_launcher</item>
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
Alecalecia answered 26/2, 2014 at 22:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.