Android 更改操作栏菜单文本

Android Change Action Bar menu text

我是 Android 的新手,我正在进入 Android 操作栏菜单文本是大写形式,但我想要文本 Change#0333 就像我在下面的示例图片中描述的那样。请问我怎样才能做到这一点?谢谢。

这是我的代码:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);

    menu.getItem(0).setTitle("change#0" + defaultmsisdn.substring(2));

    return true;
}

这是我在 res/menu 文件夹中的 main.xml 文件:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.ufoneselfcare.MainActivity" >

<item
    android:id="@+id/change_number_menu"
    android:orderInCategory="100"
    android:title="@string/action_settings"
    app:showAsAction="always|withText"/>

</menu>

在您的应用主题中(在 styles.xml 中),您将拥有一个可以自定义的应用主题。空白的可能看起来有点像这样:

<style name="MyTheme" parent="Theme.AppCompat.Light">

</style>

为了让菜单项变成小写,你需要做的是使用属性 actionMenuTextAppearance,所以使用上面的例子,你最终会得到这样的结果:

<style name="MyTheme" parent="Theme.AppCompat.Light">
    <item name="android:actionMenuTextAppearance">@style/MyMenuTextAppearance</item>
</style>

<style name="MyMenuTextAppearance" parent="TextAppearance.AppCompat.Widget.ActionBar.Menu">
    <item name="android:textAllCaps">false</item>
</style>

试试这个,希望它有效:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);

menu.getItem(0).setTitle(Html.fromHtml( "<u>change#0" + defaultmsisdn.substring(2)+"</u>"));

return true;
}