Having two single-selection groups in ActionBar doesn't work, but attaching a pop up menu instead doesn't work either

后端 未结 1 1439
失恋的感觉
失恋的感觉 2020-12-18 07:04

I am writing an Android app where the user must choose how and what to display on a graph. These options are expressed in two single-selection menu groups (radio but

相关标签:
1条回答
  • 2020-12-18 07:27

    I found an elegant way to solve this that was unfortunately not in the documentation. Add the following code to your ActionBar menu XML:

    <item android:id="@+id/menu_openothermenu"
          android:title="@string/openothermenustr"
          android:showAsAction="always">
        <menu>
            <group android:checkableBehavior="single">
                <item android:id="@+id/menu_2_choice_1" android:title="@string/2_choice_1"  android:showAsAction="never" />
                <item android:id="@+id/menu_2_choice_2" android:title="@string/2_choice_2"  android:showAsAction="never" android:checked="true" />
            </group>
         </menu>
    </item>
    

    No extra handler code or popup menu implementation is necessary for such a menu to appear.

    0 讨论(0)
提交回复
热议问题