【问题标题】:Android Change Action Bar menu textAndroid 更改操作栏菜单文本
【发布时间】:2015-05-25 13:57:45
【问题描述】:

我是 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>

【问题讨论】:

标签: android android-layout android-activity android-actionbar


【解决方案1】:

在您的应用主题(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>

【讨论】:

    【解决方案2】:

    试试这个,希望它有效:

    @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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-14
      • 2013-01-30
      • 1970-01-01
      • 2016-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      相关资源
      最近更新 更多