SearchView calSearchView = (SearchView) findViewById(R.id.sv_search_text);
if (calSearchView != null) {
try { //--拿到字节码
Class<?> argClass = calSearchView.getClass();
//--指定某个私有属性,mSearchPlate是搜索框父布局的名字
Field ownField = argClass.getDeclaredField("mSearchPlate");
//--暴力反射,只有暴力反射才能拿到私有属性
ownField.setAccessible(true);
View mView = (View) ownField.get(calSearchView);
//--设置背景
mView.setBackgroundColor(Color.TRANSPARENT);
} catch (Exception e) {
e.printStackTrace();
}
}
05-11 15:41