【问题标题】:Title of item in the menu on showing even though withText used in xml file即使在 xml 文件中使用 withText,菜单中的项目标题也会显示
【发布时间】:2015-07-02 12:14:15
【问题描述】:

我只有一个菜单项。菜单位于页面底部。虽然我在 xml 文件中使用过 withText|always。我什至尝试过 ifRoom|withText 但标题未显示在菜单中。仅显示图标。长按菜单项会显示带有项目标题的 toast。

xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="match_parent"
   android:layout_height="match_parent" >

  <item
      android:id="@+id/fbmenu"
      android:icon="@drawable/fb"
      android:title="@string/likeus"
      android:orderInCategory="400"
      android:showAsAction="withText|always" />

</menu>

Java 文件:

  public boolean onCreateOptionsMenu(android.view.Menu menu) {

    super.onCreateOptionsMenu(menu);
    MenuInflater blowup = getMenuInflater();
    blowup.inflate(R.menu.fbmenu, menu);

    return true;

这是应用程序的屏幕截图: http://i.stack.imgur.com/XD01c.png

【问题讨论】:

    标签: android menu android-actionbar title


    【解决方案1】:

    确保以支持库命名空间 (app) 为目标:

    <menu
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">
        <item
            ...
            app:showAsAction="ifRoom|withText"
            android:showAsAction="ifRoom|withText"/>
    

    【讨论】:

    • 仍然没有显示标题。这是否取决于我使用的 ADT 的 API 级别?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-16
    • 2012-01-01
    • 1970-01-01
    相关资源
    最近更新 更多