I need to design EditText with base line showed in below image and it will be change to some other color when it receives focus.!
i am using the following.
<EditText android:id="@+id/mobilenumber" android:drawableLeft="@drawable/mobile" android:drawablePadding="15dp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="number" android:background="@drawable/edt_bg" android:singleLine="true" android:textColorHint="#FFFFFF" android:hint="@string/mobilenumber" android:layout_marginTop="20dp" android:layout_gravity="center" android:padding="5dp" android:imeOptions="actionNext" android:maxLength="10" android:textColor="#ffffff" android:textCursorDrawable="@null" />
So, please guide me how to handle this.
How do I change the text color on focus in Android? For changing the baseline of EditText when it is on focus you can simply go to the colors. xml file in your project and change the "colorAccent" value.
On the Modify toolbar, click the Edit Text tool. Type ddedit and then press Enter. 2 Select the text entity. 3 In the Text dialog box, edit the text.
You can add theme for EditText
<style name="EditTextTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="colorControlNormal">@color/primary</item> <item name="colorControlActivated">@color/primary</item> <item name="colorControlHighlight">@color/primary</item> </style>
And you can use in EditText as
<EditText android:id="@+id/edtCode" android:layout_width="match_parent" android:layout_height="40dp" ....................... android:theme="@style/EditTextTheme"> </EditText>
use this in your editText style
<item name="backgroundTint">@color/focus_tint_list</item>
focus_tint_list.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:color="?attr/colorAccent"/> <item android:state_focused="false" android:color="#999999"/> </selector>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With