当我单击“默认微调器”时,它将显示弹出窗口。 然后扩展Spinner以添加一些功能,但是它完全不响应我的触摸。当我单击它时,什么也没有发生,并且弹出窗口未显示
MainActivity.kt
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, arrayOf("Aaoeuaoeuaeu", "Baoeuaoeuaoeu", "Caoeuaoeuaoeu", "Daoeuaoeuaoeu"))
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
spinner.adapter = adapter
}
}
SpinnerCustom.kt
class SpinnerCustom @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : Spinner(context, attrs, defStyleAttr)
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
tools:context=".MainActivity">
<com.pln.customspinnerwithlabel.SpinnerCustom
android:id="@+id/spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>