-5

I am new to android and I would like to know how to add a button to a toolBar and on Click of the button, I would like to open a Spinner.

Thanks

sam24
  • 99
  • 2
  • 10
  • 1
    Possible dup of http://stackoverflow.com/questions/5126141/android-open-spinner-with-single-button-click ? If you are looking for a menu on actionbar, refer to http://stackoverflow.com/questions/15518414/how-can-i-implement-custom-action-bar-with-custom-buttons-in-android. – Prasanna Nov 25 '15 at 06:18

2 Answers2

0

Since the spinner dropdown is not like the new LollyPop Design like Spinner:

So you need to add small code for the spinner control

android:dropDownVerticalOffset="-52dp" for Kitkat and below

android:dropDownVerticalOffset="0dp" for LollyPop

        <Spinner
        android:id="@+id/spinner_nav"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:dropDownVerticalOffset="@dimen/dropDownVerticalOffset" />

-> For more detail with example, visit the link :-

http://android-pratap.blogspot.in/2015/01/spinner-in-toolbar-example-in-android.html

0

its very easy Spinner before = (Spinner) findViewById(R.id.beforeSpinner); before.performClick();

it will open your spinner