Java – Android’s style editText

Android’s style editText… here is a solution to the problem.

Android’s style editText

I run Android 2.3 on my phone and noticed that many apps use ICS to edit text fields such as square up and tumblr. Does anyone know how they achieved this?

Solution

You can apply custom styles to your editing text.

Here’s how:
—Create an XML file (edit_text_holo_dark.xml)
in your drawing folder
– Put this XML code in the created file:

<?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 drawable mentioned in the above XML from the platforms folder (platform android-15) to the drawable folder of the project.

  • Create a styles.xml file in your values folder and put the following 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 the style properties to edittext:

    style=”@style/EditTextHoloDark”

Related Problems and Solutions