gpt4 book ai didi

android - Kotlin-以编程方式创建的Spinner箭头丢失

转载 作者:行者123 更新时间:2023-12-02 13:43:19 24 4
gpt4 key购买 nike

以编程方式创建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)

enter image description here

最佳答案

这是因为您为微调器选择的样式

android.R.style.Widget_Material_Spinner

与默认行为不同,此样式未包含箭头。您需要将其替换为其他样式或自己添加箭头。
val mySpinner = Spinner(
ContextThemeWrapper(this, R.style.Widget_AppCompat_Spinner_Underlined),
null,
0,
Spinner.MODE_DROPDOWN
)

试试这个

关于android - Kotlin-以编程方式创建的Spinner箭头丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61404846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com