android - Kotlin - 以编程方式创建的 Spinner 箭头丢失
问题描述
以编程方式创建后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
)
尝试这个
推荐阅读
- r - R Shiny - 按下操作按钮后在数据表中保存函数值
- highcharts - highcharts - yAxis 网格线的数量不一致
- azure - 资源 > Azure DevOps yaml 管道中未触发的存储库触发器和未禁用的默认触发器
- c++ - 使用 NVCC 编译/链接时,预处理指令 #\ 无效
- javascript - 在引用组件时在 vue 中制作 onClick="" 属性
- html - 如何让我的图像跨越多列?
- volttron - 如何在 volttron 中使用 gevent 和请求进行并发 jsonrpc
- drupal - 将补丁应用于 webform 模块返回错误
- regex - 如何使用 GAS 中的正则表达式将匹配限制在电子邮件正文的前 5 行
- android - 为什么“queueInputBuffer”中的“MediaCodec CodecException”只发生在 Android API 29 上?