1. 程式人生 > >修改SearchView搜尋框的背景線.(或著其他屬性)

修改SearchView搜尋框的背景線.(或著其他屬性)

今天是來移動的第二天,雨好大...

專案經理讓我修改一下android4.2.2日曆中的SearchView.

要求去掉當SearchView得到焦點時候出現的藍色背景線.

怎麼說呢,很苦惱,基本沒看過原始碼.而且android studio用的還不是太溜,電腦也卡才4G

雖然基本上一天等虛擬機器就得有百分之八十的時間,但是慶幸還是弄出來了.程式碼如下:

SearchView calSearchView = (SearchView)v.findViewById(R.id.calendar_search_view);
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();}}

好了.馬上下班了.