【问题标题】:Android BottomAppBar dynamic submenu configurationAndroid BottomAppBar 动态子菜单配置
【发布时间】:2021-07-10 17:21:54
【问题描述】:

短版:

我正在寻找与 onPreprareOptionMenu() 等效的 BottomAppBar,以便我可以动态配置(启用/禁用)子菜单项。

完整版:

我有一个 layout.xml:

<androidx.coordinatorlayout.widget.CoordinatorLayout>
    ...
    <com.google.android.material.bottomappbar.BottomAppBar
        ...
        app:menu="@menu/menu"
        />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

和 menu.xml:

<menu>
    <item android:id="@+id/action"
        ...
        >
        <menu>
            <item android:id="@+id/action_1"
                ...
                />
            <item android:id="@+id/action_2"
                ...
                />
        </menu>
    </item>
</menu>

现在,我想动态启用或禁用子菜单 id/action_1 或 id/action_2。有什么想法吗?

【问题讨论】:

    标签: submenu android-bottomappbar


    【解决方案1】:

    一旦您获得了对 BottomAppBar 的引用(例如,可以通过 findViewById()Data Binding 获得),就可以访问子菜单项:

    bottomAppBar.menu
            .findItem(R.id.action).subMenu
            .findItem(R.id.action_1).isEnabled = false
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-20
      • 1970-01-01
      • 2020-10-05
      • 2010-11-29
      • 2014-12-04
      相关资源
      最近更新 更多