以编程方式设置 WearableActionDrawerView 菜单

Programmatically set WearableActionDrawerView menu

是否可以在代码中设置WearableActionDrawerView的菜单(actionMenu)?

<android.support.wear.widget.drawer.WearableActionDrawerView
    android:id="@+id/drawer_action"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:actionMenu="@menu/menu_drawer"
    />

These contextual actions may be specified by using a Menu, which may be populated by either:

Specifying the app:actionMenu attribute in the XML layout file. Example:

 <android.support.wear.widget.drawer.WearableActionDrawerView
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width=”match_parent”
     android:layout_height=”match_parent”
     app:actionMenu="@menu/action_drawer" />

Getting the menu with getMenu(), and then inflating it with inflate(int, Menu). Example:

 Menu menu = actionDrawer.getMenu();
 getMenuInflater().inflate(R.menu.action_drawer, menu);

https://developer.android.com/reference/android/support/wear/widget/drawer/WearableActionDrawerView.html