Android Spinner不在棒棒糖模拟器中显示项目

时间:2019-03-21 12:34:27

标签: android

我的活动中有一个微调小部件。如果我在设备(Pie版本)上运行该应用程序,则微调器可以正常工作,但是如果我在模拟器(具有棒棒糖版本,需要工作)上运行它,则微调器根本不显示任何项目。

这是我的微调器活动代码(在onCreate中):

   spinner = (Spinner) findViewById(R.id.spinner_reminder_times);

    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(getApplicationContext(),
            R.array.reminder_times_array, android.R.layout.simple_spinner_dropdown_item);

    // Specify the layout to use when the list of choices appears
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // Apply the spinnerAdapter to the spinner
    spinner.setAdapter(spinnerAdapter);
    spinner.setOnItemSelectedListener(this);

这是已实现的方法:

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    switch (parent.getSelectedItemPosition()) {
        case 0:
            // do stuff
            break;
        case 1:
            // do stuff
            break;
        case 2:
            // do stuff
            break;
    }
}

activity_layout中的微调框xml:

        <Spinner
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/spinner_reminder_times"
            android:theme="@style/ThemeOverlay.AppCompat.Light"
            android:spinnerMode="dropdown">

        </Spinner>

可能是什么问题?它如何在我的设备上完美运行,但是在android棒棒糖模拟器上却什么也没显示? 谢谢!

2 个答案:

答案 0 :(得分:0)

enter code here
android:popupBackground="#59b0b9" 
    // try this to change the popupBackground color

<Spinner
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/spinner_reminder_times"
            android:theme="@style/ThemeOverlay.AppCompat.Light"
            android:popupBackground="#59b0b9" 
            android:spinnerMode="dropdown"/>

答案 1 :(得分:0)

创建一个名为my_spinner_dropdown_list_item.xml的新布局文件(确认有效后可能会更改textColor

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="?android:attr/spinnerDropDownItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:textColor="#FF0000"
    android:layout_height="?android:attr/dropdownListPreferredItemHeight"
    android:ellipsize="marquee"/>

并将此布局分配为Spinner的新下拉资源:

   spinner = (Spinner) findViewById(R.id.spinner_reminder_times);

    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(getApplicationContext(),
            R.array.reminder_times_array, R.layout.my_spinner_dropdown_list_item);

    // Specify the layout to use when the list of choices appears
    spinnerAdapter.setDropDownViewResource(R.layout.my_spinner_dropdown_list_item);

    // Apply the spinnerAdapter to the spinner
    spinner.setAdapter(spinnerAdapter);
    spinner.setOnItemSelectedListener(this);