1

My edit text now looks like this (like its background) http://prntscr.com/843323

and this is the code

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

 <item>
   <shape  xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
       <solid android:color="@android:color/transparent" />
   </shape>
 </item>
</selector>

How can I set underline to this edit text (for example white) when I click on it to write something.. http://prntscr.com/8434s7

2 Answers2

2

Try this:

how to change focus color of EditText in Android

Or This:

<style name="Theme.MyTheme.EditText" parent="AppTheme">
    <item name="colorControlNormal">#ff6600</item>
    <item name="colorControlActivated">#ff6600</item>
</style>


<EditText
        style="@style/TextAppearance.AppCompat.Display1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/materialDesignEditText"
        android:ems="10"
        android:hint="Normal EditText"
        android:padding="5dp"
        android:singleLine="true"
        android:textColor="#000000"
        android:textColorHint="@android:color/secondary_text_dark"
        android:textSize="15dp"
        android:theme="@style/Theme.MyTheme.EditText" />
Community
  • 1
  • 1
Ashish Tiwari
  • 2,168
  • 4
  • 30
  • 54
0

Create textfield_default

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="Color Hash Code"
        android:endColor="@color/background_material_light"
        android:angle="90" />
</shape>

create edit_text.xml in drawable

    <item
        android:state_window_focused="false"
        android:state_enabled="false"
        android:drawable="@drawable/textfield_disabled" />

    <item
        android:state_pressed="true"
        android:drawable="@drawable/textfield_pressed" />

    <item
        android:state_enabled="true"
        android:state_focused="true"
        android:drawable="@drawable/textfield_selected" />

    <item
        android:state_enabled="true"
        android:drawable="@drawable/textfield_default" />

    <item
        android:state_focused="true"
        android:drawable="@drawable/textfield_disabled_selected" />

    <item
        android:drawable="@drawable/textfield_disabled" />

</selector>

<EditText
        style="@drawable/edit_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/materialDesignEditText"
        android:ems="10"
        android:hint="Text here"
        android:padding="5dp"
        android:singleLine="true"
        android:textColor="#000000"
        android:textColorHint="@android:color/secondary_text_dark"
        android:textSize="15dp" />
Amy
  • 4,034
  • 1
  • 20
  • 34
Hemina
  • 375
  • 1
  • 11