Android: Change Spinner Dropdown view
Solution 1
Kind of reviving an old post here but the accepted answer is far from ideal. The correct way to do this is to set the Spinner to dropdown mode in your layout xml:
<Spinner
android:id="@+id/my_spinner"
...
android:spinnerMode="dropdown"/>
The available options are "dialog" and "dropdown".
Solution 2
Your application is running on old theme.
If you are using android 4.2 set android application theme (in the manifest file) to
android:theme="@android:style/Theme.Holo.Light"
OR
android:theme="@android:style/Theme.Holo.Light.DarkActionBar"
Solution 3
may be you are running in below than 4.0 , 4.0 will show you dropdown as your image
Solution 4
For the GUI Use HoloEverywhere. https://github.com/Prototik/HoloEverywhere HoloEverywhere is the best way to go if you want Holo theme on older Android then 4.0 .
And for the dropdown use android:spinnerMode="dropdown" in the layout as Stephen Kidson mentioned.
Solution 5
You can use popup like below:
spinner=(EditText)findViewById(R.id.txt_Spinner);
spinner.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
p = new Point();
p.x = location[0]+(v.getHeight());
p.y = location[1]+v.getHeight();
if (p != null)
showPopup(statusActivity.this, p);
System.out.println("show popup");
}
});
// The method that displays the popup.
private void showPopup(final Activity context, Point p) {
int popupWidth = 300;
int popupHeight = 500;
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);
// Creating the PopupWindow
popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(popupWidth);
popup.setHeight(popupHeight);
popup.setFocusable(true);
// Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
int OFFSET_X = 00;
int OFFSET_Y = 00;
// Clear the default translucent background
popup.setBackgroundDrawable(new BitmapDrawable());
// Displaying the popup at the specified location, + offsets.
popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);
((TextView)layout.findViewById(R.id.textView2)).setClickable(true);
((TextView)layout.findViewById(R.id.textView3)).setClickable(true);
((TextView)layout.findViewById(R.id.textView4)).setClickable(true);
((TextView)layout.findViewById(R.id.textView5)).setClickable(true);
((TextView)layout.findViewById(R.id.textView6)).setClickable(true);
((TextView)layout.findViewById(R.id.textView7)).setClickable(true);
((TextView)layout.findViewById(R.id.textView8)).setClickable(true);
((TextView)layout.findViewById(R.id.textView9)).setClickable(true);
}
and popup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/popup_bg"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
style="@style/text_orange_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Status"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
style="@style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="@drawable/line_white"
android:tag="Sleeping"
android:text="Sleeping" />
<TextView
android:id="@+id/textView3"
style="@style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="@drawable/line_white"
android:tag="Available"
android:text="Available" />
<TextView
android:id="@+id/textView4"
style="@style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="@drawable/line_white"
android:tag="Busy"
android:text="Busy" />
<TextView
android:id="@+id/textView5"
style="@style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="@drawable/line_white"
android:tag="At work"
android:text="At work" />
<TextView
android:id="@+id/textView6"
style="@style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="@drawable/line_white"
android:tag="Battery charge low"
android:text="Battery charge low" />
<TextView
android:id="@+id/textView7"
style="@style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="@drawable/line_white"
android:tag="In meeting"
android:text="In meeting" />
<TextView
android:id="@+id/textView8"
style="@style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="@drawable/line_white"
android:tag="TMS me later"
android:text="TMS me later" />
<TextView
android:id="@+id/textView9"
style="@style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="@drawable/line_white"
android:tag="At the toilet"
android:text="At the toilet" />
<EditText
android:id="@+id/textCustomize"
style="@style/text_blue_contains"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:tag="Customize"
android:text="Customize" />
</LinearLayout>
Sridhar
PHP developer, Android Developer, iOS Developer profile for Sridhar at Stack Overflow, Q&A for professional and enthusiast programmers http://stackoverflow.com/users/flair/1085737.png?theme=dark
Updated on August 01, 2020Comments
-
Sridhar almost 4 years
Im My application I want the below type of Spinner Dropdown view . For this type of spinner view. I wrote this code.
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.spinner, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner_obj.setAdapter(adapter);
I got this from http://developer.android.com/guide/topics/ui/controls/spinner.html But what I got is,
Please provide me the best way to do this....
-
Sridhar over 11 yearsIs there any option to fit AutocompleteTextView to Spinner?
-
Nandagopal T over 11 yearsPlease refer the above link and let me know, Are you looking for a widget like that?
-
Saty almost 11 yearsYea, Its nothing to do with theme.... Just use this attribute across any version of android!!
-
Fatima about 10 yearsWhat should one do if using android 2 ? I have the same problem with android 2.
-
Sanket Kachhela about 10 yearsinstead of spinner you can also use PopupWindow developer.android.com/reference/android/widget/PopupWindow.html
-
mr5 about 10 years
No resource identifier found for attribute 'spinnerMode' in package 'android'
, now what? It's not available on older version? -
Hamidreza Sadegh almost 10 yearssame problem, not change
-
beckah almost 9 yearsThis made my application crash :/
-
sapht over 7 yearsA crash here is probably because of conflict between Actionbar and Toolbar setup (choose the non-actionbar theme if using toolbar).