android - Android Spinner 自定义文本视图不可点击
问题描述
为什么使用自定义文本视图会阻止 Spinner 文本和项目(但不是箭头)可点击,而 Android 禁止的 Spinner 文本布局却不是这种情况?
使用时有效
val arrayAdapter = ArrayAdapter(view!!.context, android.R.layout.simple_dropdown_item_1line, spinnerItems)
arrayAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line)
XML
<Spinner
android:id="@+id/mySpinner"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:spinnerMode="dialog"/>
科特林
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 arrayAdapter = ArrayAdapter(view!!.context, R.layout.spinner_item, spinnerItems)
arrayAdapter.setDropDownViewResource(R.layout.spinner_item)
mSpinner.adapter = arrayAdapter
spinner_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/dropDownItemStyle"
android:id="@+id/my_SpinnerItem"
android:background="?android:attr/selectableItemBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:textColor="?android:attr/textColorPrimary" />
解决方案
删除这两行:
android:clickable="true"
android:focusable="true"
您的代码工作正常。
推荐阅读
- javascript - 相对 URL 不适用于节点中的 axios
- android - 如何在 android jet pack 导航控制器中将一个导航图导航到另一个导航图
- linux - ORA-12541: TNS: 没有侦听器错误即使侦听器正在运行
- jquery - JQUERY:我的对话框中的脚本不断循环
- javascript - 更改背景组件 - REACTJS
- node.js - 防止在 uncaughtExceptions 之后崩溃节点 js
- angular - Angular Material Stepper 组件阻止进入所有未访问的步骤
- javascript - 如何在模态窗口上通过 Javascript 更改 href 属性
- swift - 意外发现零
- elasticsearch - 通过多个匹配提高术语查询结果的分数