我想为我的 ActionBar SearchItem 设置背景(类似于 EditText 背景)。这是当前的操作栏。
我想将此背景设置为可绘制。
这是我创建searchItem
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.guest_list, menu);
MenuItem searchItem = menu.findItem(R.id.search);
SearchManager searchManager = (SearchManager) getActivity()
.getSystemService(Context.SEARCH_SERVICE);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
SearchView searchView = (SearchView) searchItem.getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getActivity().getComponentName()));
searchView.setIconified(true);
searchView.setSubmitButtonEnabled(true);
searchView.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
setFilter(query);
return false;
}
@Override
public boolean onQueryTextChange(String query) {
setFilter(query);
return false;
}
});
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
SearchView searchView = (SearchView) searchItem.getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getActivity().getComponentName()));
searchView.setIconified(true);
searchView.setSubmitButtonEnabled(true);
searchView.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
setFilter(query);
return false;
}
@Override
public boolean onQueryTextChange(String query) {
setFilter(query);
return false;
}
});
}
}
我试过设置背景,searchView.setBackgroundDrawable
但我没有得到我喜欢实现的东西。