In my Android application, I am using spinner, and I have loaded data from the SQLite database into the spinner, and it\'s working properly. Here is the code for that.
For someone who needs only Style
way for AppCompat
.
Result
styles.xml
...
your_spinner_layout.xml
...
...
Plus
And if you want to set android:entries
programmatically with defined style.
Try this.
AppCompatSpinner spinner = findViewById(R.id.content_spinner);
CharSequence[] entries = getResources().getTextArray(R.array.shipping_tracking_carrier_names);
ArrayAdapter adapter = new ArrayAdapter<>(spinner.getContext(), android.R.layout.simple_spinner_item, entries);
adapter.setDropDownViewResource(android.support.v7.appcompat.R.layout.support_simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
As in the code, using same Context
with the Spinner
is most important thing.
spinner.getContext()