android - 为什么 Android 上下文菜单是空的?

标签 android android-layout kotlin menu

我有上下文菜单布局:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto">
  <item
        android:id="@+id/share_btn"
        android:icon="@drawable/ic_delete_black_24dp"
        android:title=""
        app:showAsAction="always"/>
  <item
        android:id="@+id/edit_btn"
        android:icon="@drawable/ic_edit_black_24dp"
        android:title=""
        app:showAsAction="always"/>
  <item
        android:id="@+id/remove_btn"
        android:icon="@drawable/ic_delete_black_24dp"
        android:title=""
        app:showAsAction="always"/>
</menu>
还有 fragment ,我试图在其中显示菜单:
class OverviewFragment: Fragment() {

/* some code */

override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo?) {
    super.onCreateContextMenu(menu, v, menuInfo)
    this.activity!!.menuInflater.inflate(R.menu.binge_card_menu, menu)
 }
/*some code */ }
但是布局没有显示:
enter image description here
但是听众工作,如果我以编程方式制作菜单,一切都会正确显示,所以我不知道为什么。

最佳答案

发生这种情况是因为您使用空字符串作为标题:

 <item
    android:id="@+id/share_btn"
    android:title=""
    .../>

关于android - 为什么 Android 上下文菜单是空的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63576855/

相关文章:

Android - 后退按钮和 fragment 后退堆栈不起作用

dictionary - Kotlin:集合定义的差异

Android:WAITING多个任务完成

csv - jackson-dataformat-csv 不会忽略未知属性

Android:自定义可选择的 ListView 项目

android - 更改/删除图表引擎标签背景色

java - android:layout_alignParentBottom ="true"未按预期运行。

java - 以编程方式设置 PercentageRelativeLayout 中的宽高比

android - 如何在具有多个 TextView 的相对布局中保持 TextView 居中对齐

带有动态文本的 Android 对话框(API 级别 < 8)在旋转时被杀死