我的应用程序中有一个SearchView
小部件,我想问一些关于使其自定义的问题。首先,你只能通过点击搜索图标开始搜索,有什么办法可以让整个SearchView
点击?另外,有没有办法在SearchView
点击时出现这样的东西?
现在处于这种状态:
这是我的代码:
citySearch = (SearchView) findViewById(R.id.city_search_bar);
citySearch.setBackgroundResource(R.drawable.search_background);
citySearch.setOnSearchClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
citySearch.setIconifiedByDefault(true);
//citySearch.setIconified(true);
}
});
citySearch.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String text) {
((Filterable) cityListView.getAdapter()).getFilter().filter(text);
return false;
}
@Override
public boolean onQueryTextSubmit(String text) {
return false;
}
});
try
{
Field searchField = SearchView.class.getDeclaredField("mSearchButton");
searchField.setAccessible(true);
ImageView searchBtn = (ImageView)searchField.get(citySearch);
searchBtn.setImageResource(R.drawable.search_icon);
searchBtn.setScaleType(ScaleType.FIT_CENTER);
searchPlate.setBackgroundResource(R.drawable.search_background);
}
catch (NoSuchFieldException e)
{
Log.e("SEARCHSTYLEERROR",e.getMessage(),e);
}
catch (IllegalAccessException e)
{
Log.e("SEARCHSTYLEERROR",e.getMessage(),e);
}