This issue comes from the default value of ?android:attr/editTextBackground
.
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetBottom="@dimen/abc_edit_text_inset_bottom_material"
android:insetLeft="@dimen/abc_edit_text_inset_horizontal_material"
android:insetRight="@dimen/abc_edit_text_inset_horizontal_material"
android:insetTop="@dimen/abc_edit_text_inset_top_material">
<selector>
<item android:state_enabled="false">
<nine-patch
android:alpha="?android:attr/disabledAlpha"
android:src="@drawable/abc_textfield_default_mtrl_alpha"
android:tint="?attr/colorControlNormal" />
</item>
<item
android:state_focused="false"
android:state_pressed="false">
<nine-patch
android:src="@drawable/abc_textfield_default_mtrl_alpha"
android:tint="?attr/colorControlNormal" />
</item>
<item>
<nine-patch
android:src="@drawable/abc_textfield_activated_mtrl_alpha"
android:tint="?attr/colorControlActivated" />
</item>
</selector>
</inset>
As you can see the inset value for all edges of EditText is abc_edit_text_inset_top_material = 4dp
. That makes EditText has small padding around its content.
To remove that padding you should create a new EditText style with modified editTextBackground
attribute. For example:
<style name="Widget.App.TextField" parent="@style/Widget.AppCompat.EditText">
<item name="colorControlActivated">#303E44</item>
<item name="colorControlHighlight">#E5E9EC</item>
<item name="colorControlNormal">#E5E9EC</item>
<item name="editTextBackground">@drawable/background_new_edit_text</item>
<item name="android:editTextBackground">@drawable/background_new_edit_text</item>
</style>
New background_edit_text.xml
(Remember to put this file into correct drawable directory so it will not be overried such as drawable-v21...)
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:inset="@dimen/spacing_0dp">
<selector>
<item android:state_enabled="false">
<nine-patch
android:alpha="?android:attr/disabledAlpha"
android:src="@drawable/abc_textfield_default_mtrl_alpha"
android:tint="?attr/colorControlNormal" />
</item>
<item
android:state_focused="false"
android:state_pressed="false">
<nine-patch
android:src="@drawable/abc_textfield_default_mtrl_alpha"
android:tint="?attr/colorControlNormal" />
</item>
<item>
<nine-patch
android:src="@drawable/abc_textfield_activated_mtrl_alpha"
android:tint="?attr/colorControlActivated" />
</item>
</selector>
</inset>
Apply new style to your EditText
:
<EditText
android:id="@+id/edt_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Widget.App.TextField"
/>