I'm looking for style information on the Contextual Action bar (CAB). I just need to change the colour of the text in fact..
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?
Android ActionBar is a menu bar that runs across the top of the activity screen in android. Android ActionBar can contain menu items which become visible when the user clicks the “menu” button.
The app bar, also known as the action bar, is one of the most important design elements in your app's activities, because it provides a visual structure and interactive elements that are familiar to users.
On Android, toolbars are called top app bars. It's recommended to use a platform's default text alignment for toolbar titles, unless multiple action buttons are present. Titles are left-aligned by default in top app bars. Titles are center-aligned by default in navigation bars.
In Android applications, Toolbar is a kind of ViewGroup that can be placed in the XML layouts of an activity. It was introduced by the Google Android team during the release of Android Lollipop(API 21). The Toolbar is basically the advanced successor of the ActionBar.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With