一、准备
AutoCompleteTextView,是EditText+PopupWindow(ListPopupWindow)结合的:
ListPopupWindow的构造方法之一为:
public ListPopupWindow(Context context) {
this(context, null, com.android.internal.R.attr.listPopupWindowStyle, 0);
}
其中还包括
public DropDownListView(Context context, boolean hijackFocus) {
super(context, null, com.android.internal.R.attr.dropDownListViewStyle);
mHijackFocus = hijackFocus;
// TODO: Add an API to control this
setCacheColorHint(0); // Transparent, since the background drawable could be anything.
}
(在 buildDropDown()方法中创建对象DropDownListView)
所以如果更改ListPopupWindow样式,覆盖listPopupWindowStyle主题,而更改DropDownListView样式,覆盖dropDownListViewStyle主题。
二,查看资源文件
platforms/android-xx/data/res/values/attrs.xml
<attr name="dropDownListViewStyle" format="reference" />
platforms/android-xx/data/res/values/themes.xml
<item name="listPopupWindowStyle">@android:style/Widget.ListPopupWindow</item>
<item name="dropDownListViewStyle">@android:style/Widget.ListView.DropDown</item>
(有相应的HOLO的样式,这里只是列出普通的)
platforms/android-xx/data/res/values/styles.xml
<style name="Widget.ListView.DropDown">
<item name="android:cacheColorHint">@null</item>
<item name="android:divider">@android:drawable/divider_horizontal_bright_opaque</item>
</style>
<style name="Widget.Holo.Light.ListPopupWindow" parent="Widget.ListPopupWindow">
<item name="android:dropDownSelector">@android:drawable/list_selector_holo_light</item>
<item name="android:popupBackground">@android:drawable/menu_dropdown_panel_holo_light</item>
<item name="android:dropDownVerticalOffset">0dip</item>
<item name="android:dropDownHorizontalOffset">0dip</item>
<item name="android:dropDownWidth">wrap_content</item>
</style>
<style name="Widget.ListPopupWindow">
<item name="android:dropDownSelector">@android:drawable/list_selector_background</item>
<item name="android:popupBackground">@android:drawable/spinner_dropdown_background</item>
<item name="android:dropDownVerticalOffset">-10dip</item>
<item name="android:dropDownHorizontalOffset">0dip</item>
<item name="android:dropDownWidth">wrap_content</item>
</style>
三,实现
<AutoCompleteTextView
android:id="@+id/edit_search"
android:layout_width="fill_parent"
android:layout_height="32dp"
android:background="@drawable/search_et_bg"
android:drawableLeft="@drawable/search_icon"
android:drawablePadding="2dp"
android:dropDownSelector="@color/transparent"
android:dropDownVerticalOffset="3dp"
android:hint="@string/search_hint"
android:imeOptions="actionSearch"
android:inputType="textFilter"
android:paddingRight="25dp"
android:singleLine="true"
android:textColor="#000"
android:textColorHint="#CCC"
android:textSize="14sp" />
suggestAdapter = new SuggestAdapter(this, suggestWords, 10);
searchEt.setDropDownBackgroundResoter);
searchEt.setOnItemClickListener();urce(R.drawable.transparent_drawable);
searchEt.setAdapter(suggestAdaper)
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
...
<item name="android:dropDownListViewStyle">@style/suggest_style</item>
</style>
<style name="suggest_style" parent="@android:style/Widget.ListView.DropDown">
<item name="android:background">@drawable/transparent_drawable</item>
<item name="android:cacheColorHint">@android:color/transparent</item>
<item name="android:divider">@null</item>
<item name="android:listSelector">@android:color/transparent</item>
<item name="android:scrollingCache">false</item>
<item name="android:fadingEdge">none</item>
</style>
其中:scrollingCache来源于:
<declare-styleable name="AbsListView">
<!-- Drawable used to indicate the currently selected item in the list. -->
<attr name="listSelector" format="color|reference" />
<!-- When set to true, the selector will be drawn over the selected item.
Otherwise the selector is drawn behind the selected item. The default
value is false. -->
<attr name="drawSelectorOnTop" format="boolean" />
<!-- Used by ListView and GridView to stack their content from the bottom. -->
<attr name="stackFromBottom" format="boolean" />
<!-- When set to true, the list uses a drawing cache during scrolling.
This makes the rendering faster but uses more memory. The default
value is true. -->
<attr name="scrollingCache" format="boolean" />
.......
另外两篇文章
http://blog.stylingandroid.com/archives/1285
http://www.javacodegeeks.com/2013/06/android-listview-context-menu-actionmode-callback.html