0

I have a buttons and I want to make them look like a spinner. I've found this post from 2011: Android: Drawing a button as a spinner

And none of the solutions worked for me.

It's better if I could use my customed background. Those are the buttons:

 <Button
            android:id="@+id/new_msn_act_type"
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:background="@drawable/button_border"
            android:onClick="showPopup"
            android:padding="6dp"
            android:text="Order Type"
            android:textColor="@color/colorPrimary" />

<Button
                android:id="@+id/new_msn_datetimepick"
                android:layout_width="120dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="5dp"
                android:background="@drawable/button_border"
                android:onClick="pickDateTime"
                android:padding="6dp"
                android:text="Date and Time"
                android:textColor="@color/colorPrimary" />

I tried each one of the solutions suggested in the post, including

                style="?android:attr/spinnerStyle"
And they didn't work. How can I solve it ? Thanks

I need it to be a Button, because I want to use drawable style as background, and I want it to open PopupMenu and I worked hard for the popup to present icons correctly...

jonb
  • 845
  • 1
  • 13
  • 36
  • It would be far easier making a spinner look like a button – Martin De Simone Feb 23 '18 at 22:41
  • The easiest thing may be to use a spinner and override its onClick. A lot of buttons you see aren't buttons, but are other views like TextViews or FrameLayouts with an onClick set. – Gabe Sechan Feb 23 '18 at 22:56
  • @GabeSechan it sounded tempting, I created Spinner, and added: android:onClick="showPopup" (Like the original button's) But it didn't work: Caused by: java.lang.RuntimeException: Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead – jonb Feb 23 '18 at 23:00
  • Also adding Icon to my button will also help. How can I do it ? – jonb Feb 24 '18 at 08:08

1 Answers1

0

I solved it with:

android:drawableRight="@drawable/arrow_down_float"

You can also choose custom drawables

jonb
  • 845
  • 1
  • 13
  • 36