How do I style the menu items text in the Android Toolbar? - android

How can I style the menu item text with the new Android Toolbar, like you used to be able to do with android:actionMenuTextAppearance?
I tried using that same property in the toolbar style, and it appears not to do anything at all.

For styling AppCompat toolbar popups:
<style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar" >
<!-- your other theme overrides here -->
<item name="textAppearanceLargePopupMenu">#style/MyLargePopupStyle</item>
<item name="textAppearanceSmallPopupMenu">#style/MySmallPopupStyle</item>
</style>
<style name="MyLargePopupStyle" parent="#style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Large">
<item name="android:textSize">18sp</item>
<item name="android:textStyle">italic</item>
<item name="android:textColor">#color/my_popup_text_color</item>
</style>
<style name="MySmallPopupStyle" parent="#style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Small">
<item name="android:textSize">12sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/my_popup_text_color</item>
</style>

Try using the "app" namespace:
xmlns:app="http://schemas.android.com/apk/res-auto"
app:actionMenuTextAppearance="#style/myAppearance"

Have you tried the styling in the menu xml resource file?
Go to your menu resource (usually in the res/menu folder) and select which item you want to change appearance of. Then use android:textAppearance to set the appearance

Related

How to change CAB style in Android?

I'm trying to change the Contextual Action Bar style using this snippet
<style name="AppTheme.Reader" parent="AppTheme">
<item name="android:actionModeStyle">#style/AppTheme.ActionMode</item>
<item name="actionModeStyle">#style/AppTheme.ActionMode</item>
</style>
<style name="AppTheme.ActionMode" parent="Widget.AppCompat.ActionMode">
<item name="background">#color/white</item>
<item name="titleTextStyle">#style/AppTheme.ActionMode.Title</item>
<item name="subtitleTextStyle">#style/TextAppearance.AppCompat.Widget.ActionMode.Subtitle</item>
</style>
And setting the theme in the right activity
android:theme="#style/AppTheme.Reader"
Then I've used a
TextView.setCustomSelectionActionModeCallback()
To intercept the selected text, but when it comes up the CAB it has the default style and seems that my custom hasn't been applied.
Where am I wrong?
Try to use the latest support lib (as of now: v23.4.0). Depends where your parent "AppTheme" inherits from, it may or may not work but if you try to inherit from the "AppCompat" theme the following should work and once you see the white background you can fill in the rest of the attributes:
<style name="AppTheme" parent="Theme.AppCompat">
<item name="actionModeStyle">#style/ActionModeTheme</item>
</style>
<style name="ActionModeTheme" parent="#style/Widget.AppCompat.ActionMode">
<item name="background">#color/white</item>
</style>
Of course assuming <color name="white">#fff</color> is defined in colors.xml

Overflow menu row customization

I am wanting to customise the rows of the overflow menu in the action bar. I found a great blog post explaining how to go about doing this, which seem simple enough. The link is below.
http://scriptedpapers.com/2014/08/12/android-action-bar-overflow-menu-customization/
I am specifically wanting to change the background colour of the overflow menu rows so the theme that I am using looks like the following:
<resources>
<!--the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/CustomActionBar</item>
<item name="android:homeAsUpIndicator">#drawable/upcaret</item>
<item name="android:actionOverflowButtonStyle">#style/CustomOverflowButton</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<!--ActionBar style -->
<style name="CustomActionBar" parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/customBlue</item>
</style>
<style name="CustomOverflowButton" parent="#android:style/Widget.Holo.Light.ActionButton.Overflow">
<item name="android:src">#drawable/overflowbutton</item>
</style>
<style name="PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#color/customBlue</item>
</style>
Applying this theme to the application, the background colour of the overflow menu remains the same colour as the default for Holo.Light.DarkActionBar, despite setting a custom popupMenuStyle.
For my project, the minSdkVersion is 15 and targetSdkVersion is 19.
Does anyone have any ideas?
Thanks.
Try specifying a 9-patch drawable instead of a color.
Go here and choose the color that you want your rows to be by selecting a color from the "Popup color" drop-down.
The only file you need from the zip is menu_dropdown_panel.9.png.
Make sure to place this file in your various drawable-xxxx folders.
Then use it like this:
<style name="PopupMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel</item>
</style>
If it still doesn't work, add this to the above:
Add this line to your main theme (CustomActionBarTheme):
<item name="android:actionBarWidgetTheme">#style/PopupWrapper</item>
Then add this:
<style name="PopupWrapper" parent="#android:style/Theme.Holo">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>

Styling my app with custom colors

I'm trying to apply some styles to my app. I've created a custom theme for the ActionBar using this actionbarstylegenerator.
But I want to change also in my app, the stock blue Holo color, to a red one, at least on buttons.
So, I have the custom theme for the ActionBar (Compat), and for the other side, a custom theme to change the Holo color.
In my app, I have defined the custom theme for the Actionbar, and I want to set the custom Holo theme inside the Actionbar's theme, but I don't know how to call, or where can I find the item name's whose define the variable you want to modify.
This is, I need to set this:
<style name="ColorTheme" parent="android:Theme.Black">
<item name="android:checkboxStyle">#style/CheckBoxColorTheme</item>
<item name="android:buttonStyle">#style/ButtonColorTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonColorTheme</item>
</style>
Inside of this:
<style name="Theme.CustomActionBarTheme" parent="#style/Theme.AppCompat">
<item name="actionBarItemBackground">#drawable/ab_selectable_background</item>
<item name="popupMenuStyle">#style/PopupMenu</item>
<item name="dropDownListViewStyle">#style/DropDownListView</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle</item>
<item name="actionDropDownStyle">#style/DropDownNav</item>
<item name="actionBarStyle">#style/ActionBar.Transparent</item>
<item name="actionModeBackground">#drawable/cab_background_top_customactionbartheme</item>
<item name="actionModeSplitBackground">#drawable/cab_background_bottom_customactionbartheme</item>
<item name="actionModeCloseButtonStyle">#style/ActionButton.CloseMode</item>
</style>
Maybe you need to do this?
<style name="ColorTheme" parent="Theme.CustomActionBarTheme">
<item name="android:checkboxStyle">#style/CheckBoxColorTheme</item>
<item name="android:buttonStyle">#style/ButtonColorTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonColorTheme</item>

Android ActionBar MenuItem LowerCase

I want to make MenuItem title in the ActionBar to LowerCase.
my menu.xml
<item android:id="#+id/register"
android:title="Register"
android:showAsAction="ifRoom|withText"/>
<item android:id="#+id/unregister"
android:title="Unregister"
android:showAsAction="ifRoom|withText"/>
On the ActionBar it sees "REGISTER" and "UNREGISTER", but I want that it sees as "Register" and "Unregister".
Is it possible to make first letter upper and next letters lower at MenuItem?
And how I can do that?
Solution for native ActionBar implementation:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme.Holo">
<item name="android:actionMenuTextAppearance">#style/MyMenuTextAppearance</item>
</style>
<style name="MyMenuTextAppearance" parent="android:TextAppearance.Holo.Widget.ActionBar.Menu">
<item name="android:textAllCaps">false</item>
</style>
</resources>
If you are using ActionBarSherlock there are two different approaches:
1) Create boolean resource abs__config_actionMenuItemAllCaps and set it to false:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="abs__config_actionMenuItemAllCaps">false</bool>
</resources>
2) Or create theme with overriden actionMenuTextAppearance and use it in AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="Theme.Sherlock">
<item name="actionMenuTextAppearance">#style/MyMenuTextAppearance</item>
<item name="android:actionMenuTextAppearance">#style/MyMenuTextAppearance</item>
</style>
<style name="MyMenuTextAppearance" parent="TextAppearance.Sherlock.Widget.ActionBar.Menu">
<item name="android:textAllCaps">false</item>
</style>
</resources>
PLEASE NOTE: there is bug in ActionBarSherlock that forces MenuItem to be upper case on pre-ICS (https://github.com/JakeWharton/ActionBarSherlock/issues/969). I've submitted patch but it is not merged at the moment. For now you can use my fork: https://github.com/alexander-mironov/ActionBarSherlock/tree/dev, I will update this answer when my code is merged in the main repository.
UPDATE: my fix has been merged into main ActionBarSherlock repository.
Add the following to one of your values xml files -
<bool name="abc_config_actionMenuItemAllCaps">false</bool>
Just to complete the answer, if you're using AppCompat the parent style is:
<style name="MyMenuTextAppearance" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textAllCaps">false</item>
</style>
For making the menu text to lowercase like "MENU ITEM" to "Menu Item" here is my solution.
In res >> values >> styles.xml add the following:
<style name="MenuItemTextAppearance" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="textAllCaps">false</item>
</style>
After you can call it on your AppTheme:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">...</item>
<item name="colorPrimaryDark">...</item>
<item name="colorAccent">...</item>
<item name="actionMenuTextAppearance">#style/MenuItemTextAppearance</item>
</style>
I hope this helps. :)
I tried some of the other answers here but to no luck (I'm not using action bar sherlock). As mentioned in the comments, in the newer support libraries, the above solutions don't seem to work. To solve this issue, I added my own actionLayout to the Menu Items.
<item
android:id="#+id/done"
app:showAsAction="always"
android:title="#string/yourTitle"/>
Then in my code I did something like this.
final MenuItem done = menu.findItem(R.id.done);
done.setActionView(R.layout.menu_item_kingfisher_text_view);
TextView doneTextView = (TextView) done.getActionView();
Then you can do what you want with the text view and avoid the text being all caps. This is definitely not ideal, but if you need a workaround for this issue, this does work.
From source code in android.support.v7.internal.view.menu.ListMenuItemView
//Set text appearance in constructor from style
...
mTextAppearance = a.getResourceId(R.styleable.MenuView_android_itemTextAppearance, -1);
...
//Apply text appearance to view item
mTitleView = (TextView) findViewById(R.id.title);
if (mTextAppearance != -1) {
mTitleView.setTextAppearance(mTextAppearanceContext, mTextAppearance);
}
In project:
Create popup theme and apply it on popup creation for some custom popup if it's planned to use this appearance across whole application then put it to main application theme.
<style name="PopupTheme" parent="#style/Theme.AppCompat.Light.NoActionBar">
<item name="android:itemTextAppearance">#style/FontStyle</item>
</style>
...
Context context = new ContextThemeWrapper(getActivity(), R.style.PopupTheme);
MenuPopupHelper optionsMenu = new MenuPopupHelper(context, menuBuilder, anchorView);
...
add theme to toolbar with textAllCaps
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ToolBarStyle"
app:titleTextColor="#color/colorAccent"
app:subtitleTextColor="#color/colorAccent"
/>
styles.xml
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="android:textAllCaps">false</item>
</style>

Define custom Logo for ActionBar (different than Logo) in XML?

I want to make a Actionbar_style.xml for my app and I would like to use a logo, different than my app logo / icon.
How to change it programmatcially is clear: Change logo that appears in Android ActionBar programatically
But like this I would need to code this into each activity.
Is there a xml tag to define a custom Actionbarlogo in xml already?
my Customstyles.xml
<style name="CustomActionBar0" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/action_bg0</item>
</style>
android styles.xml seems not to have it...
<style name="Widget.ActionBar">
<item name="android:background">#android:drawable/action_bar_background</item>
<item name="android:displayOptions">useLogo|showHome|showTitle</item>
<item name="android:divider">#android:drawable/action_bar_divider</item>
<item name="android:height">?android:attr/actionBarSize</item>
<item name="android:paddingLeft">0dip</item>
<item name="android:paddingTop">0dip</item>
<item name="android:paddingRight">0dip</item>
<item name="android:paddingBottom">0dip</item>
<item name="android:titleTextStyle">#android:style/TextAppearance.Widget.ActionBar.Title</item>
<item name="android:subtitleTextStyle">#android:style/TextAppearance.Widget.ActionBar.Subtitle</item>
<item name="android:progressBarStyle">#android:style/Widget.ProgressBar.Horizontal</item>
<item name="android:indeterminateProgressStyle">#android:style/Widget.ProgressBar.Small</item>
<item name="android:homeLayout">#android:layout/action_bar_home</item>
</style>
Just set a value for the android:icon attribute
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/AppTheme.ActionBarStyle</item>
</style>
<style name="AppTheme.ActionBarStyle" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:titleTextStyle">#style/AppTheme.ActionBar.TitleTextStyle</item>
<item name="android:icon">#drawable/ic_home</item>
<item name="android:indeterminateProgressStyle">#style/IndeterminateProgress</item>
</style>
You don't style the logo in the your style XML, you simply use android:logo in your Manifest, then use setDisplayUseLogoEnabled() to set it in the ActionBar. Here's a project, from Google, that shows you how to switch between the two. http://code.google.com/p/styled-action-bar/
Sounds like you need to use a custom layout for the action bar, that way you can define a whatever you want for logo image.
Action bar / ActionbarSherlock style
<style name="ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="displayOptions">showCustom</item>
<item name="android:displayOptions">showCustom</item>
<item name="customNavigationLayout">#layout/action_bar_home_icon_default</item>
<item name="android:customNavigationLayout">#layout/action_bar_home_icon_default</item>
</style>
#layout/action_bar_home_icon_default is your custom layout, with your custom logo
Yes. You may set different logo for different activities. Here is the sample code in manifest file.
<activity
android:name="MyActivity"
***android:icon="#drawable/logo"***
android:label="#string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait" />
Hope this help. Cheers!

Categories

Resources