0
我试图实现以下和编辑文本,当验证失败时,编辑文本行将颜色更改为红色,颜色更改从中心向边缘生成动画。如何将动画应用于Android中的视图的setBackground颜色属性?
我认为设置为,隐藏编辑文本的底线,下面添加编辑文本视图来显示行
<android.support.design.widget.TextInputLayout
android:id="@+id/fpet_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="horizontal"
app:errorEnabled="false"
app:hintAnimationEnabled="true"
android:theme="@style/TextLabel">
<EditText
android:id="@+id/fpet_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHighlight="@color/blue"
android:background="@null"
android:textColorLink="@color/blue"
android:paddingTop="5dp"
android:textSize="18dp"
/>
</android.support.design.widget.TextInputLayout>
<ImageView
android:id="@+id/fpet_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="5dp"
android:layout_below="@id/fpet_text_input_layout"
android:background="@color/grey"></ImageView>
我已经尝试了多种方法,但仍无法在完全正确拿到。以下是我迄今
使用规模的动画尝试和做设定背景前开始动画。但在这种情况下,线正在重绘,而不是只是改变颜色
我试过使用值动画,但我找不到适当的方式来应用自定义动画,而不是淡入淡出的行为。
Integer colorFrom = getResources().getColor(R.color.grey); Integer colorTo = getResources().getColor(color); ValueAnimator colorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimator.setDuration(1000); colorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { underLine.setBackgroundColor((Integer)animator.getAnimatedValue()); } }); colorAnimator.start();
我真的很感激任何帮助,我能为我曾尝试添加更多的代码,我不想做的问题太长。 Thanks
工程就像魅力!非常感谢你,这非常有帮助! –