Adding a spinner to your activity
In layout XML:
Basic Spinner Example
It is a type of dropdown input.
Firstly in layout
Now Secondly populate values in spinner
There are mainly two ways to populate values in
- From XML itself
create a array.xml in values directory under res.
Now add this line in sppiner XML
- You can also add values via JAVA
if you are using in
cityArea = (Spinner) findViewById(R.id.cityArea);
else if you are using in
Now create a
This will look like
According to the device Android version it will render style
Following are some of the default themes
If an app does not explicitly request a theme in its manifest, Android System will determine the default theme based on the app’s targetSdkVersion to maintain the app’s original expectations:
|Android SDK Version||Default Theme|
|Version < 11||@android:style/Theme|
|Version between 11 and 13||@android:style/Theme.Holo|
|14 and higher||@android:style/Theme.DeviceDefault|
Spinner can be easily customized with the help of xml
Create a custom background in XML and use it.
easily get the position and other details of the selected item in spinner
Change the text color of the selected item in spinner
This can be done in two ways in XML
This will change the selected item color in the popup.
and from JAVA do this (in the setOnItemSelectedListener(...))
This modified text is an extract of the original Stack Overflow Documentation created by following contributors
and released under CC BY-SA 3.0