更改AutoCompleteTextView下划线的颜色 [英] Change the color of the underline of AutoCompleteTextView

查看:399
本文介绍了更改AutoCompleteTextView下划线的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将AutoCompleteTextView设置为无法聚焦,但是我不希望它将下划线的颜色从蓝色更改为灰色.有没有办法重写它,并将下划线颜色更改回原始的蓝色,同时仍使AutoCompleteTextView不能聚焦?

I have my AutoCompleteTextView set to un-focusable but I don't want it to change the color of the underline from blue to grey. Is there a way to override it and change the underline color back to the original blue color while still keeping the AutoCompleteTextView unfocusable?

推荐答案

这只是创建和应用自定义样式的问题.第一步是转到 http://android-holo-colors.com/并生成自动完成的可绘制对象和样式.打开生成的存档,并将文件名中包含"edit_text"和"textfield"的所有可绘制对象复制到您的项目中.

This is just a matter of creating and applying a custom style. The first step is to go to http://android-holo-colors.com/ and generate the drawables and style for Autocomplete. Open the generated archive and copy all of the drawables that contain "edit_text" and "textfield" in their file name into your project.

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

Now you'll have to go through all of the dpi-specific drawable directories and overwrite the files named:

apptheme_textfield_default_holo_light.9.png

文件来自相同目录,命名为:

with the file from the same directory named:

apptheme_textfield_activated_holo_light.9.png

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

Now you need to create a the custom style. For API 11+ it will look like this:

  <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继承的替代样式.

For older API levels, you'll need an alternative style that inherits from android:Widget.AutoCompleteTextView.

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

You should just be able to apply this style now in your layouts:

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

这篇关于更改AutoCompleteTextView下划线的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆