不能比标题中说清楚得多。我有一个由文本输入布局包装的EditText。当EditText失去焦点时,我试图触发一个事件。但是,一旦应用了事件侦听器,TextInputLayout就不再为文本设置动画,它只是位于editText行,直到输入信息为止,此时它会进行动画处理。任何人都可以给我一些见解,为什么会发生这种情况?
编辑:布局文件。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/card_drawable"
android:gravity="center"
android:padding="11dp"
android:text="The fields below will be used to calculate your training maxes. Please enter your best rep record, or 1RM, for each lift. Training maxes will be determined using the following formula provided in Beyond 5/3/1: \n(Weight Lifted x Reps X .0333 + Weight Lifted)" />
<LinearLayout
android:id="@+id/squat_container"
style="@style/linear_layout_style">
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="@+id/squatWeight_editText"
style="@style/editText_floating_label"
android:hint="Squat Weight" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/txtInputLayoutSquat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="@+id/squatReps_editText"
style="@style/editText_floating_label"
android:hint="Repetitons" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/bench_container"
style="@style/linear_layout_style">
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="@+id/bechpressWeight_editText"
style="@style/editText_floating_label"
android:hint="Bench Press Weight" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="@+id/benchpressReps_editText"
style="@style/editText_floating_label"
android:hint="Repetitons" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/deadlift_container"
style="@style/linear_layout_style">
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="@+id/deadliftWeight_editText"
style="@style/editText_floating_label"
android:hint="Deadlift Weight" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="@+id/deadliftReps_editText"
style="@style/editText_floating_label"
android:hint="Repetitons" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/ohp_container"
style="@style/linear_layout_style">
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="@+id/ohpWeight_editText"
style="@style/editText_floating_label"
android:hint="Overhead Press Weight" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="@+id/ohpReps_editText"
style="@style/editText_floating_label"
android:hint="Repetitons" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</LinearLayout>
答案 0 :(得分:5)
这并没有解决问题,但确实提供了一些见解(如果我找到解决方案,我会更新),但似乎动画提示依赖于OnFocusChangedListener
,它会被覆盖当你添加自己的监听器。
https://code.google.com/p/android/issues/detail?id=175344
修改强>
每https://code.google.com/p/android/issues/detail?id=178693 ...
我们现在正在使用不同的方式来确定EditText
是否有针对性。现在做类似的事情:
TextInputLayout inputLayout = ...;
EditText editText = inputLayout.getEditText();
final OnFocusChangeListener existing = editText.getOnFocusChangeListener();
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View view, boolean focused) {
existing.onFocusChange(view, focused);
// Your custom logic
}
});
答案 1 :(得分:5)
我不得不处理同样的问题。
我使用的解决方法是使用自定义EditText并在触发onFocusChanged方法时为其调用自定义侦听器。
自定义EditText (未显示Boiler plate代码)
public class EditTextPlus extends AppCompatEditText {
//This is the custom listener you will use
public OnFocusChangeListener customListener;
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
if (customListener != null) {
customListener.onFocusChange(this, focused);
}
}
}
在活动/片段中
yourEditText.customListener = new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
//Do your stuff
}
}
不要忘记在xml中使用自定义EditText,而不是默认的EditText。