android – Style button as Spinner-ThrowExceptions

Exception or error:

I want that my button looks like a spinner, because I will show a special dialog if the button is clicked. I use Theme.MaterialComponents and tried following but it’s not working:

<Button
            android:id="@+id/btMusclegroups"
            style= "?spinnerStyle"// or style="@style/Widget.AppCompat.Spinner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

The button still looks solid and not like a spinner.

Desired result

I want that my button looks the same as following Spinner:

<Spinner
            android:id="@+id/btMusclegroups"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

I could use a Spinner with OnTouchListener and a dummy adapter (I don’t need the adapter, my dialog knows all the data it needs already) but I’d prefer the above way – is this somehow achievable?

How to solve:

Create a container and add an image view containing the dropdown symbol for the spinner and a button. Add an OnClickListener to the button that calls the dialog and updates the text of the button. Don’t forget to style the button as NoBackground.

Leave a Reply

Your email address will not be published. Required fields are marked *