更改AutoCompleteTextView的下划线的颜色

时间:2014-07-02 16:02:52

标签: android autocompletetextview

我将AutoCompleteTextView设置为无法调焦,但我不希望它将下划线的颜色从蓝色更改为灰色。有没有办法覆盖它并将下划线颜色更改回原始的蓝色,同时仍然保持AutoCompleteTextView不可聚焦?

1 个答案:

答案 0 :(得分:1)

这只是创建和应用自定义样式的问题。第一步是转到http://android-holo-colors.com/并生成自动填充的drawable和样式。打开生成的存档,并将其文件名中包含“edit_text”和“textfield”的所有drawable复制到项目中。

现在,您必须浏览所有特定于dpi的可绘制目录并覆盖名为的文件:

apptheme_textfield_default_holo_light.9.png

使用名为:

的同一目录中的文件
apptheme_textfield_activated_holo_light.9.png

现在您需要创建自定义样式。对于API 11+,它将如下所示:

  <style name="MyAutoCompleteTextView" parent="android:Widget.Holo.Light.AutoCompleteTextView">
      <item name="android:background">@drawable/apptheme_edit_text_holo_light</item>
  </style>

对于较旧的API级别,您需要一种继承自android:Widget.AutoCompleteTextView的替代样式。

您现在应该可以在布局中应用此样式:

<AutoCompleteTextView
    android:focusable="false"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/MyAutoCompleteTextView"/>
相关问题