这是一种可能性。
定义查询建议行布局,例如R.layout.li_query_suggestion,看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@android:id/text1"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:gravity="center_vertical"
android:minHeight="56dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="@android:color/black"
tools:text="Blah blah blah"/>
请注意,背景颜色为白色,文本颜色为黑色。当然,您可以更改这些值。
然后,在您的光标适配器中,将您创建的布局指定为行布局。例如:
CursorAdapter suggestionAdapter = new SimpleCursorAdapter(
getActivity(),
R.layout.li_query_suggestion,
null,
new String[]{"name"},
new int[]{android.R.id.text1},
0);
这将为您提供如下所示的内容:
仅供参考,我当前的主题是这样的:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/light_blue_500</item>
<item name="colorPrimaryDark">@color/light_blue_700</item>
<item name="colorAccent">@color/pink_a200</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="searchViewStyle">@style/CustomSearchView</item>
</style>