简体   繁体   English

样式editText为android

[英]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. 我在手机上运行Android 2.3并注意到很多使用ICS编辑文本字段的应用程序,例如square up和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) - 在drawables文件夹中创建一个xml文件(edit_text_holo_dark.xml)
- Put this xml code inside the file created: - 将此xml代码放在创建的文件中:

<?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. 将上述xml中提到的drawables从platforms文件夹(平台android-15)复制到项目的drawable文件夹中。

  • Create a styles.xml file inside your values folder and put this code: 在values文件夹中创建styles.xml文件并放入以下代码:

     <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属性添加到edittext:

    style="@style/EditTextHoloDark" 风格= “@风格/ 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. 这应该不难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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