用于API级别8的ICS样式EditText

Man*_*ath 1 android android-edittext android-holo-everywhere

如何为ICS中的Holo主题设置EditText的样式,使其与API级别为8的设备兼容.

我尝试了以下代码,但它与API 8不兼容.

<EditText
        android:id="@+id/editText1"
        style="@android:style/Widget.Holo.EditText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)

Ahm*_*mad 7

你可以使用HoloEveryWhere.

或者你可以这样做:

<style name="MyTheme" parent="@android:style/Theme">
    <item name="android:editTextBackground">@drawable/my_edittext</item>
</style>
Run Code Online (Sandbox Code Playgroud)

my_edittext.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_light" />
    <item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/textfield_disabled_holo_light" />
    <item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/textfield_activated_holo_light" />
    <item android:state_enabled="true" android:state_activated="true" android:drawable="@drawable/textfield_focused_holo_light" />
    <item android:state_enabled="true" android:drawable="@drawable/textfield_default_holo_light" />
    <item android:state_focused="true" android:drawable="@drawable/textfield_disabled_focused_holo_light" />
    <item android:drawable="@drawable/textfield_disabled_holo_light" />
</selector>
Run Code Online (Sandbox Code Playgroud)

您可以在SDK文件夹中找到所提到的drawable.