[英]Style editText for android
我在手機上運行Android 2.3並注意到很多使用ICS編輯文本字段的應用程序,例如square up和tumblr。 有誰知道他們是如何使用來實現這一目標的?
您可以將自定義樣式應用於編輯文本。
這是如何做:
- 在drawables文件夾中創建一個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中提到的drawables從platforms文件夾(平台android-15)復制到項目的drawable文件夾中。
在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>
最后在布局文件中,將style屬性添加到edittext:
風格= “@風格/ EditTextHoloDark”
請閱讀本文,它可能會幫助你 //Dead
上面的鏈接現在無效, 你可能會看一下這個
他們很可能將資源從新平台復制到他們的應用程序中。 因此,您需要將與編輯文本相關的文件復制到您的應用中,並將其應用到您的編輯框中。 這應該不難。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.