How do I create an Android Spinner as a popup?

后端 未结 12 1777
梦如初夏
梦如初夏 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:55

    This is from the Android SDK source code. As you can see you have a special constructor to create a Spinner with the specified mode you wanna use.

    Hope it will help you :)

     /**
         * Construct a new spinner with the given context's theme, the supplied attribute set,
         * and default style. mode may be one of {@link #MODE_DIALOG} or
         * {@link #MODE_DROPDOWN} and determines how the user will select choices from the spinner.
         *
         * @param context The Context the view is running in, through which it can
         *        access the current theme, resources, etc.
         * @param attrs The attributes of the XML tag that is inflating the view.
         * @param defStyle The default style to apply to this view. If 0, no style
         *        will be applied (beyond what is included in the theme). This may
         *        either be an attribute resource, whose value will be retrieved
         *        from the current theme, or an explicit style resource.
         * @param mode Constant describing how the user will select choices from the spinner.
         * 
         * @see #MODE_DIALOG
         * @see #MODE_DROPDOWN
         */
        public Spinner(Context context, AttributeSet attrs, int defStyle, int mode) {
            super(context, attrs, defStyle);
    

提交回复
热议问题