TextInputLayout中浮动标签改变状态时如何执行动作?
how to perform action when the floating label change the state in TextInputLayout?
我在 TextInputLayout 中有一个 Edittext。我想这样做,当我点击这个 textinputlayout 时,日历也是 open.but 在我的情况下,浮动标签改变状态,当我点击 edittext 时,日历是 opening.but 我不想要为此,我希望当用户第一次单击 TextInputLayout 时,浮动标签会发生变化,并且日历也会打开 it.can 有人告诉我我该怎么做吗??
这是我的 xml :-
<android.support.design.widget.TextInputLayout
android:id="@+id/til_dob"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/_10sdp"
android:clickable="true"
android:textColorHint="@color/colorBlack">
<EditText
android:id="@+id/DateOfBirth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/date"
android:inputType="none"
android:maxLines="1"
android:singleLine="true"
android:textSize="15sp" />
</android.support.design.widget.TextInputLayout>
这是我在编辑文本上的点击监听器:-
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.DateOfBirth:
new DatePickerDialog(getContext(), date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show();
break;
}
}
您应该使用 OnFocusChangeListener 在第一次单击 TextInputLayout 时做出反应(这意味着 TextInputLayout 中的 EditText 获得焦点)
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override public void onFocusChange(View v, boolean hasFocus) {
//Open the calendar
new DatePickerDialog(getContext(), date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
});
"lambda version" 将是:
editText.setOnFocusChangeListener((v, hasFocus) ->
new DatePickerDialog(getContext(), date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show());
我在 TextInputLayout 中有一个 Edittext。我想这样做,当我点击这个 textinputlayout 时,日历也是 open.but 在我的情况下,浮动标签改变状态,当我点击 edittext 时,日历是 opening.but 我不想要为此,我希望当用户第一次单击 TextInputLayout 时,浮动标签会发生变化,并且日历也会打开 it.can 有人告诉我我该怎么做吗??
这是我的 xml :-
<android.support.design.widget.TextInputLayout
android:id="@+id/til_dob"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/_10sdp"
android:clickable="true"
android:textColorHint="@color/colorBlack">
<EditText
android:id="@+id/DateOfBirth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/date"
android:inputType="none"
android:maxLines="1"
android:singleLine="true"
android:textSize="15sp" />
</android.support.design.widget.TextInputLayout>
这是我在编辑文本上的点击监听器:-
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.DateOfBirth:
new DatePickerDialog(getContext(), date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show();
break;
}
}
您应该使用 OnFocusChangeListener 在第一次单击 TextInputLayout 时做出反应(这意味着 TextInputLayout 中的 EditText 获得焦点)
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override public void onFocusChange(View v, boolean hasFocus) {
//Open the calendar
new DatePickerDialog(getContext(), date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
});
"lambda version" 将是:
editText.setOnFocusChangeListener((v, hasFocus) ->
new DatePickerDialog(getContext(), date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show());