以下是我的SearchView使用Android Support Library version 23.0.4:
的样子以下是使用Support Library 24.0.0:
的样子如何让我的SearchView在24.0.0中正确显示文字?这不是文字颜色问题仅供参考,我adjusted text color of the EditText无效。您还可以看到它缺少" x"右边的按钮。
更新
以下是我用于搜索菜单的XML:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/search"
android:icon="@drawable/nav_icon_search"
android:title="@string/search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView" />
</menu>
以下是我在onCreateOptionsMenu中使用的代码:
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_location_list, menu);
this.configureSearchView(menu);
super.onCreateOptionsMenu(menu, inflater);
}
private void configureSearchView(Menu menu) {
MenuItem search = menu.findItem(R.id.search);
MenuItemCompat.setOnActionExpandListener(search, this);
this.mSearchView = (SearchView)
MenuItemCompat.getActionView(search);
this.mSearchView.setOnQueryTextListener(this);
this.mSearchView.setOnCloseListener(this);
this.mSearchView.setSubmitButtonEnabled(false);
this.mSearchView.setIconifiedByDefault(true);
this.mSearchMenuItem = search;
}