Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText background base line color changing based on its focus in android

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.!

enter image description here

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.

like image 712
koti Avatar asked Sep 04 '14 09:09

koti


People also ask

How to change the Edit text color on focusing in android?

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.

How do you edit text in line?

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.


2 Answers

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> 
like image 116
jobi mg Avatar answered Sep 21 '22 13:09

jobi mg


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> 
like image 42
Slashbin Avatar answered Sep 20 '22 13:09

Slashbin