Android different EditText backgrounds for different states using shapes, selector or list Android different EditText backgrounds for different states using shapes, selector or list android android

Android different EditText backgrounds for different states using shapes, selector or list


I suggest to use NinePatch images to customize your EditText. Here goes an example based on my code:

The Selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android">  <item android:state_window_focused="false" android:state_enabled="true"        android:drawable="@drawable/twitter_im_edittext_normal" />  <item android:state_window_focused="false" android:state_enabled="false"        android:drawable="@drawable/twitter_im_edittext_normal" />  <item android:state_pressed="true" android:drawable="@drawable/twitter_im_edittext_normal" />  <item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/twitter_im_edittext_focused" />  <item android:state_enabled="true" android:drawable="@drawable/twitter_im_edittext_normal" />  <item android:state_focused="true" android:drawable="@drawable/twitter_im_edittext_focused" />  <item android:drawable="@drawable/twitter_im_edittext_normal" /></selector>

Use selector the same way you used in your code, set it to background of your EditText.

Images:

twitter_im_edittext_focused.9.png twitter_im_edittext_focused.9.png

twitter_im_edittext_normal.9.png twitter_im_edittext_normal.9.png

More about NinePatch images you can found here.

Hope it helps.


A short version of the accepted answer

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_enabled="true" android:state_focused="true"        android:drawable="@drawable/edit_text_background_focused" />    <item android:drawable="@drawable/edit_text_background_normal" /></selector>


I think the problem is that your cursor is above the left 'border / wall' of the editText box and is not visible due to the overlap.

What I did was to add some padding for the text and this moved the cursor and text more 'inward' and it then became visible.

Try adding this to your editText:

android:paddingLeft="8dp"