suggestionsRowLayout
对我也没有起作用。
在我的情况下,我只需要更改每行的背景颜色和文本颜色。
因此,我只需修改从 newView()
返回的 View 的布局即可。
public class SuggestionsAdapter extends CursorAdapter
{
public SuggestionsAdapter(Context context, Cursor cursor)
{
super(context, cursor, false);
}
@Override
public void bindView(View view, Context context, Cursor cursor)
{
TextView tv = (TextView) view.findViewById(R.id.item);
tv.setText(cursor.getString(COL_NAME));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent)
{
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.search_item, parent, false);
return view;
}
}
search_item.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="12dp" >
<TextView
android:id="@+id/item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/red" />
</LinearLayout>
当然,您可以将背景设置为可选择的绘制器以显示点击高亮。
<style name="MySearchViewStyle" parent="Widget.AppCompat.SearchView"> <item name="suggestionRowLayout">@layout/searchview_dropdown</item> </style>
- MrBrightside