ContextMenu with footer view (to add checkbox for

2019-04-16 02:42发布

问题:

Is there a standard way to add a footer to a context menu, in which I can add a checkbox to make the selected option the default one? Similar to the context menu that comes up when choosing the default home screen for example.

From the Api docs for ContextMenu I see that you can set a header view, but not a footer view. Also the setCheckable / setGroupCheckable methods don't seem to help much here.

Does this need to be done via a custom (alert) dialog? I would be wondering if nobody has yet developed such a component yet in case it's not possible through the standard SDK api. Any standalone open source component out there (beside the Android source itself)?

回答1:

The best I've come up with is using an AlertDialog

alert.getListView().addFooterView(...); and overriding it's onItemSelected method.