Android implementation of Edittext custom style

I am creating custom editing text in android by adding xml to drawable res.it as below.

<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <!-- Border --> <item> <shape> <solid android:color="@color/gray"></solid> </shape> </item> <!-- Body --> <item android:bottom="1dp" android:right="0dp" android:left="0dp" android:top="0dp"> <shape> <solid android:color="@color/white"></solid> </shape> </item> </layer-list> <EditText android:id="@+id/edt_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@drawable/edittext" android:digits="1234567890" android:ellipsize="end" android:focusableInTouchMode="true" android:inputType="numberPassword" android:singleLine="true" android:textColor="@color/dark" /> 

so I just want edittext to be a single line. But when I implement this, for a few seconds the top border of the edittext is visible, and then it goes away ... I really don’t understand why this is happening ...

+5
source share
1 answer

Create res / drawable / custom_edittext_style.xml

 <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/apptheme_textfield_default_holo_light" /> <item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/apptheme_textfield_disabled_holo_light" /> <item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/apptheme_textfield_activated_holo_light" /> <item android:state_enabled="true" android:state_activated="true" android:drawable="@drawable/apptheme_textfield_focused_holo_light" /> <item android:state_enabled="true" android:drawable="@drawable/apptheme_textfield_default_holo_light" /> <item android:state_focused="true" android:drawable="@drawable/apptheme_textfield_disabled_focused_holo_light" /> <item android:drawable="@drawable/apptheme_textfield_disabled_holo_light" /> 

And add all the required drawable files to the dropdown folder.

  <EditText android:id="@+id/edt_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@drawable/custom_edittext_style" android:digits="1234567890" android:ellipsize="end" android:focusableInTouchMode="true" android:inputType="numberPassword" android:singleLine="true" android:textColor="@color/dark" /> 
+1
source

All Articles