【发布时间】:2020-04-24 13:37:06
【问题描述】:
为什么每当我为我的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(ContextThemeWrapper(view!!.context, R.style.Widget_AppCompat_Spinner_Underlined),
null,
0,
Spinner.MODE_DROPDOWN
)
val arrayAdapter = ArrayAdapter(view!!.context, R.layout.tv_spinner_item, spinnerItems)
arrayAdapter.setDropDownViewResource(R.layout.tv_spinner_item)
mySpinner.adapter = arrayAdapter
mFrameLayout.addView(mySpinner)
自定义下拉项
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/dropDownItemStyle"
android:id="@+id/my_spinner_item"
android:background="?android:attr/selectableItemBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true" />
【问题讨论】:
-
能否将
tv_spinner_item和my_spinner_item布局文件添加到问题中?
标签: android kotlin android-spinner