How do I create an Android Spinner as a popup?

后端 未结 12 1767
梦如初夏
梦如初夏 2020-12-02 09:20

I want to bring up a spinner dialog when the user taps a menu item to allow the user to select an item.

Do I need a separate dialog for this or can I use Spinner dir

12条回答
  •  暖寄归人
    2020-12-02 09:50

    You can use a spinner and set the spinnerMode to dialog, and set the layout_width and layout_height to 0, so that the main view does not show, only the dialog (dropdown view). Call performClick in the button click listener.

        mButtonAdd.setOnClickListener(view -> {
            spinnerAddToList.performClick();
        });
    

    Layout:

        
    

    The advantage of this is you can customize your spinner any way you want.

    See my answer here to customize spinner: Overriding dropdown list style for Spinner in Dialog mode

提交回复
热议问题