如何创建在res \菜单一个TextView? [英] How to create a TextView in the res\menu?

查看:126
本文介绍了如何创建在res \菜单一个TextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在菜单中创建一个TextView,将文本动态设置。现在我的菜单上有这样的:

I'm trying to create a TextView in the menu, the text is to be set dynamically. Right now my menu has this:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_search"
        android:actionViewClass="android.widget.SearchView"
        android:icon="@android:drawable/ic_menu_search"
        android:showAsAction="ifRoom"
        android:title="Search"/>
    <item
        android:id="@+id/action_sync"
        android:icon="@drawable/ic_menu_refresh"
        android:showAsAction="ifRoom"
        android:title="Sync"/>

</menu>

我如何创建它只有文字的项目?

How can I create an item which has only text?

推荐答案

如果你想只显示文字,根本就不在menu.xml文件添加一个图标。如果你想改变code中的文字,你可以在你的活动回调象这样在做这样的prepareOptionsMenu():

If you want to just show text, simply don't add an icon in menu.xml. If you want to change the text in code, you can do so in the onPrepareOptionsMenu() on your activity callback as such:

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem myItem = menu.findItem(R.id.the_item);
    myItem.setTitle("bla");
    return true;
}

这篇关于如何创建在res \菜单一个TextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆