我想在菜单中创建一个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;
}
上一篇:为什么使用 JAX-RS/Jersey?JAX、RS、Jersey
下一篇:在 Jackson/Jersey JAVA 上发布带有多个参数 JSON 和 String 的请求多个、参数、Jersey、Jackson