When defining a spinner in code, you can set the mode to 'dialog' or 'dropdown':
Spinner(Context context, int mode) Construct a new spinner with the given context's theme and the supplied mode of displaying choices.
But I can't find this option wh开发者_高级运维en defining my layout in XML. Did I just miss it, or is this not possible in XML?
As of API level 11, you can use
<Spinner style="@android:style/Widget.Spinner.DropDown" ... />
or
<Spinner android:spinnerMode="dropdown" ... />
No, according to the reference found here this is not possible. There is no corresponding XML attribute listed. Like other things as setting 24h mode for a timepicker, which is not possible in XML.
If you're using the API level 10 or lower just remove android:spinnerMode and style from your XML file.
To use SpinnerMode
Xml attribute and work on API Level 11 or higher.
you need to create your own style for spinner.
1] put in themes.xml
file in values
Folder :
<style name="spinner_style" >
<item name="spinnerMode">dialog</item>
</style>
2] put in themes.xml
file in values-v11
Folder and values-v14
Folder :
<style name="spinner_style" >
<item name="android:spinnerMode">dialog</item>
</style>
3] then use your style in Spinner
xml tag
<Spinner android:id="@+id/my_spinner"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
style="@style/spinner_style"/>
精彩评论