I have a view with some input fields, one of those is a TextInputEditText
with a datepicker
associated which shows up when the field is selected. 问题是,在第一次点击时,该TextInputEditText
字段获得焦点,并且需要第二次点击才能显示datepicker
.
这就是字段的定义方式
<android.support.design.widget.TextInputLayout
android:id="@+id/wExpiresAt"
style="@style/AppTheme.TextInputLayout"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:errorTextAppearance="@style/AppTheme.Text.ErrorText"
app:hintTextAppearance="@style/AppTheme.Text.HintText"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/wMessage">
<android.support.design.widget.TextInputEditText
android:id="@+id/tvExpiresAt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/tv_pick_date_ph"
android:imeOptions="actionNext"
android:textSize="18sp" />
</android.support.design.widget.TextInputLayout>
在活动中:
val mExpiresAt: TextInputEditText = findViewById(R.id.tvExpiresAt)
mExpiresAt!!.setOnClickListener {
val cal = Calendar.getInstance()
val year = cal.get(Calendar.YEAR)
val month = cal.get(Calendar.MONTH)
val day = cal.get(Calendar.DAY_OF_MONTH)
val dialog = DatePickerDialog(
this@NewMessageActivity,
android.R.style.Theme_Material_Light_Dialog_MinWidth,
mDateSetListener,
year, month, day)
dialog.show()
}
我的猜测是问题是由TextInputLayout
包装引起的TextInputEditText
,第一次点击触发动画,将提示字符串从文本字段移动到其顶部并将焦点放在字段本身,第二次点击触发与文本字段并datepicker
出现。如何在第一次点击时获取所有事件?