可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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 when defining my layout in XML. Did I just miss it, or is this not possible in XML?
回答1:
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.
回答2:
As of API level 11, you can use
<Spinner style="@android:style/Widget.Spinner.DropDown" ... />
or
<Spinner android:spinnerMode="dropdown" ... />
回答3:
If you're using the API level 10 or lower just remove android:spinnerMode and style from your XML file.
回答4:
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"/>