Style editText for android

android, java

Solution

You can apply custom style to your edit text.

Here's how: - Create a xml file in your drawables folder (edit_text_holo_dark.xml) - Put this xml code inside the file created:

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

<item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/textfield_default_holo_dark" />
<item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/textfield_disabled_holo_dark" />
<item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/textfield_activated_holo_dark" />
<item android:state_enabled="true" android:state_activated="true" android:drawable="@drawable/textfield_focused_holo_dark" />
<item android:state_enabled="true" android:drawable="@drawable/textfield_default_holo_dark" />
<item android:state_focused="true" android:drawable="@drawable/textfield_disabled_focused_holo_dark" />
<item android:drawable="@drawable/textfield_disabled_holo_dark" />
</selector>

Copy the drawables mentioned in the above xml from platforms folder (platform android-15) to your project's drawable folder.

Create a styles.xml file inside your values folder and put this code:

<style name="EditTextHoloDark" parent="android:style/Widget.EditText">
    <item name="android:background">@drawable/edit_text_holo_dark</item>
    <item name="android:textColor">#ffffff</item>
</style>

Finally in your layout file, add style attribute to edittext:

style="@style/EditTextHoloDark"

Problem

I'm running Android 2.3 on my phone and notice a lot of apps using ICS edit Text fields such as square up and tumblr. Do anyone know how they are using to achieve this ?

Original source