简体   繁体   中英

Style editText for android

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 ?

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"

Most likely they had copied the resources from the new platform into their app. So you need to copy files related to edit text into your app and apply those to your edit boxes. It should not be that difficult to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM