如何显示自定义菜单标题?

问题描述

我在清单 android:theme="@style/Theme.Custom" 中为 MainActivity 设置了自定义主题,即:<style name="Theme.Custom" parent="Theme.MaterialComponents.Light.NoActionBar"> <...>

此 MainActivity 充当导航主机片段,在导航地图中,我已将另一个片段设置为启动。在我调用的那个片段中:

override fun onCreateView(<..>

    setHasOptionsMenu(true)
    (activity as AppCompatActivity?)!!.supportActionBar?.title = "title"

    return <...>
}

onCreateOptionMenu <... ..>
onOptionsItemSelected <..>

我在该菜单中指定的所有元素都会出现。当我的 MainActivity 的主题是 "Theme.MaterialComponents.Light.DarkActionBar" 时出现标题,但是当我将其设置为我的自定义时,标题不会出现任何内容。这是为什么?

更新:

enter image description here

假设我想要这个操作栏。我的问题是“操作栏”文本没有出现。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)