样式编辑文本为安卓



我在手机上运行Android 2.3,注意到很多使用ICS编辑文本字段的应用程序,如方形和tumblr。有谁知道他们是如何实现这一目标的?

您可以将自定义样式应用于编辑文本。

方法如下:
- 在可绘制对象文件夹中创建一个 xml 文件 (edit_text_holo_dark.xml)
- 将此 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>


  • 将上述 xml 中提到的可绘制对象从平台文件夹(平台 android-15)复制到项目的可绘制对象文件夹。

  • 在 values.xml 文件夹中创建一个 styles 文件,并将以下代码放入:

    <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>
    


  • 最后,在布局文件中,将样式属性添加到编辑文本:

    style="@style/EditTextHoloDark"

请阅读此内容,它可能会帮助您//Dead

上面的链接现在无效,你可以看看这个

他们很可能已经将新平台的资源复制到他们的应用程序中。因此,您需要将与编辑文本相关的文件复制到您的应用程序中,并将其应用于您的编辑框。这应该不难做到。

最新更新