我不會去太多的細節,因爲有一個很好的張貼在這裏:here在適應searchview和爲什麼上述答案不起作用。
如果你想改變你的「X」,下面的工作來改變顏色
int crossId = searchView.getContext().getResources().getIdentifier("android:id/search_close_btn", null, null); // Getting the 'search_plate' LinearLayout.
ImageView image = (ImageView) searchView.findViewById(crossId);
Drawable d = image.getDrawable();
d.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
如果你想改變圖標
int crossId = searchView.getContext().getResources().getIdentifier("android:id/search_close_btn", null, null); // Getting the 'search_plate' LinearLayout.
ImageView image = (ImageView) searchView.findViewById(crossId);
image.setImageResource(R.drawable.NEW_ICON_HERE);
如果您繪製圖標所在?它在你的可繪製文件夾中嗎? – GrIsHu
是它在可繪製的文件夾中 – jason
查看我的答案。 @jason – GrIsHu