Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 326
Vladimir Avatar asked Jun 11 '13 13:06

Vladimir


4 Answers

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.

like image 190
Alexander Mironov Avatar answered Nov 06 '22 17:11

Alexander Mironov


Add the following to one of your values xml files -

<bool name="abc_config_actionMenuItemAllCaps">false</bool>
like image 26
adarsh Avatar answered Nov 06 '22 18:11

adarsh


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>
like image 25
Enrichman Avatar answered Nov 06 '22 18:11

Enrichman


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

like image 16
Rhusfer Avatar answered Nov 06 '22 18:11

Rhusfer