问题
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?
回答1:
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.
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
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>
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"/>
来源:https://stackoverflow.com/questions/24535907/change-the-color-of-the-underline-of-autocompletetextview