I need TextInputEditText bottom line color like below.
Default color => Gray
If user enter text, line color should remain as Blue. Currently, if i enter input in first edittext and go to other edittext, first one becoming gray again.
Edittext is Empty => Gray
I also require default hint animation of
TextInputLayout
, So, can't useEditText
. I implemented this by usingTextWatcher
like here but not working.
Here is my code
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/EditScreenTextInputLayoutStyle"
app:hintTextAppearance="@style/etHintText">
<android.support.design.widget.TextInputEditText
android:id="@+id/etAddress"
style="@style/et_14_blk_sngl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="text"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
Style :
<style name="EditScreenTextInputLayoutStyle">
<item name="colorControlNormal">@color/gray</item>
<item name="colorControlActivated">@color/blue</item>
<item name="colorControlHighlight">@color/blue</item></style>
And,
private void UpdateLineColor()
{
if (!TextUtils.IsEmpty(this.Text))
{
DrawableCompat.SetTint(this.Background, ContextCompat.GetColor(this.Context, Resource.Color.blue));
if (Build.VERSION.SdkInt >= Build.VERSION_CODES.Lollipop)
{
ColorStateList colorStateList = ColorStateList.ValueOf(Resources.GetColor(Resource.Color.blue));
this.BackgroundTintList = colorStateList;
ViewCompat.SetBackgroundTintList(this, colorStateList);
}
this.Background.SetColorFilter(Resources.GetColor(Resource.Color.blue), PorterDuff.Mode.SrcAtop);
}
else
{
DrawableCompat.SetTint(this.Background, ContextCompat.GetColor(this.Context, Resource.Color.gray));
if (Build.VERSION.SdkInt >= Build.VERSION_CODES.Lollipop)
{
ColorStateList colorStateList = ColorStateList.ValueOf(Resources.GetColor(Resource.Color.gray));
this.BackgroundTintList = colorStateList;
ViewCompat.SetBackgroundTintList(this, colorStateList);
}
this.Background.SetColorFilter(Resources.GetColor(Resource.Color.gray), PorterDuff.Mode.SrcAtop);
}
}