Java – style EditText for Android

I ran Android 2.3 on my phone and noticed many applications that use ICs to edit text fields, such as square up and Tumblr Who knows how they use to achieve this goal?

Solution

You can apply custom styles to edit text

How to do this: – create an XML file (edit_text_holo_dark. XML) in the drawables 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 drawables mentioned in the above XML from the platforms folder (android-15 platform) to the drawables folder of the project. > Create styles in the values folder XML file and enter 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 attribute to EditText:

Style = "@ style / edittextholodark"

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>