47

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?

Vladimir
  • 549
  • 1
  • 5
  • 8

7 Answers7

49

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.

Alexander Mironov
  • 3,095
  • 26
  • 28
26

Add the following to one of your values xml files -

<bool name="abc_config_actionMenuItemAllCaps">false</bool>
adarsh
  • 269
  • 3
  • 2
25

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>
Enrichman
  • 11,157
  • 11
  • 67
  • 101
  • 11
    This is having no effect for me with AppCompat on an S3 and Nexus 4. I can change other actionMenuTextAppearance attributes such as text size and style. However, the all caps remain. I have rev 21.0.1 of the support library. – Mike Ortiz Nov 17 '14 at 23:45
  • @Mike: It worked with older support libraries. But somehow it does not work in 21.0.x anymore. I wonder why. Maybe they do not want that to work at all? Kind of annoying. – Patrick Boos Nov 24 '14 at 10:56
  • I am facing the same problem. – jagmohan Dec 04 '14 at 05:50
  • Did anyone ever find a solution here? I'm suffering from the same issue. – Zach Sperske Jul 01 '15 at 00:17
  • 2
    When upgrading to support rev 23.3.0 I had to use textAllCaps without the android package. false – Lucas Arrefelt Apr 20 '16 at 07:06
  • yup i'm seeing you need to drop the android package in both places: @style/MyMenuTextAppearance with false – hmac Nov 09 '16 at 10:07
17

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. :)

Rhusfer
  • 571
  • 1
  • 9
  • 14
5

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.

Zach Sperske
  • 658
  • 9
  • 28
0

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);
...
Nikolay Nikiforchuk
  • 1,998
  • 24
  • 20
0

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>
denizs
  • 693
  • 1
  • 7
  • 20