如何自定义在Android AutoCompleteTextView下拉 [英] How to customize AutoCompleteTextView dropdown on Android

查看:143
本文介绍了如何自定义在Android AutoCompleteTextView下拉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如果是可以做到的,可以自定义从 AutoCompleteTextView 选中时下拉的颜色。我可以定制一切,但不是所选择的颜色,即 - 它保持不变

I would like to know how, if it can be done, to customize the color of the dropdown from the AutoCompleteTextView when selected. I can customize everything else, but not the selected color ie - it stays the same.

活动

ArrayAdapter<String> adap = new ArrayAdapter<String>(this, R.layout.row, strings);
autoNewBird = (AutoCompleteTextView)findViewById(R.id.autoCompleteBirdName);
autoNewBird.setAdapter(adap);

row.xml:

row.xml:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/birdtext"
android:padding="5dip"  
android:background="@drawable/custom_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/spinner_item" 
android:gravity="center_vertical"
android:layout_gravity="center_vertical" android:lines="1"/>

和绘制custom_spinner.xml(在绘制文件夹)

and the drawable custom_spinner.xml (in drawable folder)

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="@drawable/listback" />
<item android:state_window_focused="false" android:state_enabled="false"
    android:drawable="@drawable/listback" />
<item android:state_pressed="true" android:drawable="@drawable/threebythree" />
<item android:state_enabled="true" android:state_focused="true"
android:drawable="@drawable/threebythree" />              
<item android:state_enabled="true" android:drawable="@drawable/listback" />
<item android:state_focused="true" android:drawable="@drawable/listback" />
<item android:drawable="@drawable/listback" />
</selector>

这适用于旋转器下拉列表中,但是对于一个 AutoCompleteTextView ,选择的时候,它不会改变颜色像微调下拉列表。

This works for a spinner dropdown, but for an AutoCompleteTextView, when selected, it does not change color like the spinner dropdown.

任何帮助,或者有这方面的经验将是AP preciated。

Any help, or experience with this would be appreciated.

推荐答案

我想我想通了,或者说我在做什么错。 在一个主题,我把这样的:

I guess I figured it out, or rather what I was doing wrong. In a theme I put this:

<item name="android:autoCompleteTextViewStyle">@style/custom_autocomplete</item>

和风格(或相关部分):

and the style is(or relevant part):

<item name="android:dropDownSelector">@drawable/custom_spinner</item>

和custom_spinner以上。

and the custom_spinner is above.

希望这可以帮助别人。

这篇关于如何自定义在Android AutoCompleteTextView下拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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