How to create a TextView in the res\menu?

android, android-menu

Solution

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

Problem

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?

Original source

Related problems