I want to make a Spinner in android which will have the following dropdown list style:
My onCreate method does
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.day, android.R.layout.simple_spinner_item);
and
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
to make the previous image's spinner dropdown list.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.day, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
I followed the instructions from this site . But I don't get the same dropdown list. The setDropDownViewResource and the adapter have no effect.
The only difference i find with the instructions is that the example's style is "android:Theme.Light", while my theme style is Theme.AppCompat.Light . So, i wonder if the AppCompat is the problem.
try this to solve your issue
xml:
<Spinner
android:id="@+id/spinner1"
android:layout_width="275dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:spinnerMode="dropdown"
style="@android:style/Widget.Spinner"
android:layout_marginTop="20dp" />
code:
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.day, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.select_dialog_singlechoie);
spinner.setAdapter(adapter);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.