样式 searchView(白色)
Styling searchView (white color)
有没有办法隐藏此屏幕截图中显示的图标 http://s2.postimg.org/8nip77c7d/aaaa.png
.........(看起来我的 post 主要是代码,所以我添加了这个)
这是我的代码:
sv = new SearchView(context);
MenuItem mi = menu.findItem(R.id.action_search);
mi.setActionView(sv);
int searchIconId = sv.getContext().getResources().
getIdentifier("android:id/search_button", null, null);
ImageView searchIcon = (ImageView) sv.findViewById(searchIconId);
searchIcon.setImageResource(R.drawable.ic_action_action_search);
try {
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
sv.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
Field searchField = null;
searchField = SearchView.class.getDeclaredField("mCloseButton");
searchField.setAccessible(true);
ImageView closeBtn = null;
closeBtn = (ImageView) searchField.get(sv);
closeBtn.setImageResource(R.drawable.ic_action_content_clear);
int searchTextViewId = sv.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
TextView searchTextView = (TextView) sv.findViewById(searchTextViewId);
searchTextView.setTextColor(Color.parseColor("#ffffff"));
} catch (NoSuchFieldException e)
{
Log.e("sv",e.getMessage(),e);
}
catch (IllegalAccessException e)
{
Log.e("sv",e.getMessage(),e);
}
我通过编写提示解决了这个问题,方法是在前一个代码的末尾添加这段代码
searchTextView.setTextColor(Color.parseColor("#ffffff"));
searchTextView.setHintTextColor(Color.parseColor("#aaffffff"));
searchTextView.setHint(getString(R.string.recherche));
此处截图http://s16.postimg.org/yt1wogfx1/Screenshot_2015_04_13_22_11_35.png
有没有办法隐藏此屏幕截图中显示的图标 http://s2.postimg.org/8nip77c7d/aaaa.png .........(看起来我的 post 主要是代码,所以我添加了这个) 这是我的代码:
sv = new SearchView(context);
MenuItem mi = menu.findItem(R.id.action_search);
mi.setActionView(sv);
int searchIconId = sv.getContext().getResources().
getIdentifier("android:id/search_button", null, null);
ImageView searchIcon = (ImageView) sv.findViewById(searchIconId);
searchIcon.setImageResource(R.drawable.ic_action_action_search);
try {
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
sv.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
Field searchField = null;
searchField = SearchView.class.getDeclaredField("mCloseButton");
searchField.setAccessible(true);
ImageView closeBtn = null;
closeBtn = (ImageView) searchField.get(sv);
closeBtn.setImageResource(R.drawable.ic_action_content_clear);
int searchTextViewId = sv.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
TextView searchTextView = (TextView) sv.findViewById(searchTextViewId);
searchTextView.setTextColor(Color.parseColor("#ffffff"));
} catch (NoSuchFieldException e)
{
Log.e("sv",e.getMessage(),e);
}
catch (IllegalAccessException e)
{
Log.e("sv",e.getMessage(),e);
}
我通过编写提示解决了这个问题,方法是在前一个代码的末尾添加这段代码
searchTextView.setTextColor(Color.parseColor("#ffffff"));
searchTextView.setHintTextColor(Color.parseColor("#aaffffff"));
searchTextView.setHint(getString(R.string.recherche));
此处截图http://s16.postimg.org/yt1wogfx1/Screenshot_2015_04_13_22_11_35.png