Kotlin - 以编程方式创建的微调器箭头丢失

Kotlin - Programmatically created Spinner arrow missing

以编程方式创建 Spinner 后,通常位于右侧的下拉箭头由于某种原因没有出现。为什么箭头不见了,如何显示?

        spinnerItems = arrayOf(
            "Cathedral of the Intercession of the Most Holy Theotokos on the Moat",
            "Ferapontov Monastery",
            "Historic Monuments of Novgorod and Surroundings",
            "Golden Mountains of Altai",
            "Historic Centre of Saint Petersburg and Related Groups of Monuments",
            "Bogoroditse-Smolensky Monastery",
            "White Monuments of Vladimir and Suzdal"
        )

        val mySpinner =
            Spinner(view!!.context, null, android.R.style.Widget_Material_Spinner, Spinner.MODE_DROPDOWN)

        val arrayAdapter = ArrayAdapter(view!!.context, android.R.layout.simple_dropdown_item_1line, spinnerItems)
        arrayAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line)

        mySpinner.adapter = arrayAdapter

        mFrameLayout.addView(mySpinner)

这是因为您为旋转器选择的样式

android.R.style.Widget_Material_Spinner

与默认行为不同,此样式中不包含箭头。需要换成其他样式或者自己加箭头

val mySpinner = Spinner(
        ContextThemeWrapper(this, R.style.Widget_AppCompat_Spinner_Underlined),
        null,
        0,
        Spinner.MODE_DROPDOWN
    )

试试这个