spinner shows like dialog

*爱你&永不变心* 提交于 2019-12-03 15:50:10

For the information Dropdown spinner that you shown in Image 3 is applicable from version 3.0 and above. For previous versions like 2.2 and 2.3 it will open like dialog. It will automatically show dropdown in versions above 2.3

Styles will be automatically added if you choose android version 4.0 or above.

<!--
    Base application theme for API 14+. This theme completely replaces
    AppBaseTheme from BOTH res/values/styles.xml and
    res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.DeviceDefault.Light.DarkActionBar">
    <!-- API 14 theme customizations can go here. -->
</style>    

Refrence code

    severitySpinner = (Spinner) findViewById(R.id.spinnerSeverity);
    severityAdapter = ArrayAdapter.createFromResource(this,
            R.array.severity_arrays, android.R.layout.simple_spinner_item);
    severityAdapter
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    severitySpinner.setAdapter(severityAdapter);

Edit

<application
        android:icon="@drawable/appicon"
        android:label="Test"
        android:theme="@style/AppTheme" >

Late but may be useful to other people, you can simply set the spinnerMode to dropdown:

android:spinnerMode="dropdown"

Else, if you decided you fancied a change and wanted dialog in the future just change the mode to dialog!

Zulfiqar Chandio

in manifest file change theme to android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" and in xml file set style for spinner style="@style/MyDropDownNav" and in style file add style.

<!-- style the list navigation -->
<style name="MyDropDownNav" parent="android:style/Widget.Holo.Light.Spinner">
    <item name="android:popupBackground">@drawable/bg_popup</item>
    <item name="android:dropDownSelector">@drawable/top_layout</item>
</style>

Just change the code like this:

ArrayAdapter<String> spinnerMenu = new ArrayAdapter<String>(
                    RegisterActivity.this, R.layout.spinner_item, list);
            // TODO Auto-generated method stub
            spinnerMenu
                    .setDropDownViewResource(android.R.layout.simple_list_item_single_choice);

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