Spinner功能在Android 6.0.1上无效

act*_*e93 12 android android-spinner android-6.0-marshmallow

Spinner用来显示一些值.而奇怪的问题是

下拉列表中正确显示,但是当我从下拉列表中选择任何项目,未在框中显示.

奇怪的是,此功能适用于所有Android操作系统before 6.0.1(i.e. 6.0.0 and previous).我也尝试AppCompatSpinner了,结果是一样的.

main.xml中:

<Spinner
    android:id="@+id/spinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="0.3"
    android:entries="@array/values" />
Run Code Online (Sandbox Code Playgroud)

Main.java:

Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setSelection(5); // Not displaying 5th item, Yes! there are more than 5 items.
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        spinner.setSelection(position);
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {
        spinner.setSelection(5);
    }
});
Run Code Online (Sandbox Code Playgroud)

act*_*e93 7

我回答自己的问题很奇怪.但经过大量研究后我终于找到了解决方案.

解:

我之前写的代码没有错.这只是Android OS 6.0.1中内部填充的问题

Android OS 6.0.1的发布中,他们对内部填充进行了一些更改Spinner.

在阅读了有关 SO的相关问题后,我调整了我的Spinner宽度并使其在所有Android OS版本中都可见.