set spinner mode in XML

偶尔善良 提交于 2019-12-06 05:15:20

问题


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"/>


来源:https://stackoverflow.com/questions/5613632/set-spinner-mode-in-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!