這是一種可能性。
定義查詢建議行佈局,例如, 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>
你嘗試克里斯詛咒的建議嗎? http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html。查找部分標題SearchView Widget。 – 2014-12-03 19:05:59