public void initSearchViewActions() {
searchView.setMaxWidth(Integer.MAX_VALUE);
searchView.onActionViewExpanded();
searchView.setQueryHint(getString(R.string.search_tips));
searchView.setOnQueryTextListener(this);
searchView.setSubmitButtonEnabled(true);
try {
Field field = searchView.getClass().getDeclaredField("mGoButton");
field.setAccessible(true);
ImageView mGoButton = (ImageView) field.get(searchView);
mGoButton.setImageResource(R.mipmap.ic_menu_search);
Field fieldSearch = searchView.getClass().getDeclaredField("mSearchButton");
fieldSearch.setAccessible(true);
ImageView mSearchButton = (ImageView) field.get(searchView);
mSearchButton.setVisibility(View.GONE);
Field fieldClear = searchView.getClass().getDeclaredField("mCloseButton");
fieldClear.setAccessible(true);
ImageView mCloseButton = (ImageView) fieldClear.get(searchView);
mCloseButton.setImageResource(R.mipmap.ic_menu_clear);
int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
TextView textView = (TextView) searchView.findViewById(id);
textView.setTextColor(Color.WHITE);
textView.setHintTextColor(Color.parseColor("#FFFFFF"));
Field ownField = searchView.getClass().getDeclaredField("mSearchPlate"); // 注意mSearchPlate的背景是stateListDrawable(不同状态不同的图片)
// 所以不能用BitmapDrawable
// setAccessible 它是用来设置是否有权限访问反射类中的私有属性的,只有设置为true时才可以访问,默认为false
ownField.setAccessible(true);
View mView = (View) ownField.get(searchView);
mView.setBackgroundColor(Color.TRANSPARENT);
} catch (Exception e) {
LogUtil.e(e.getMessage(), e);
}
int completeViewId = searchView.getResources().getIdentifier("android:id/search_src_text",null,null);
mAutoCompleteTextView = (AutoCompleteTextView) searchView.findViewById(completeViewId);
mAutoCompleteTextView.setThreshold(0);
mAutoCompleteTextView.setTextColor(Color.parseColor("#ffffff"));
mAutoCompleteTextView.setHintTextColor(Color.parseColor("#ffffff"));
}