I am trying to change one simple icon from the android default one to some that I want.
As you see the first picture is when searchview is not expanded and the icon just sits in the action bar. When it is tapped/clicked that's what the bottom image shows. Everything here is good except the dark search icon. All I want is to change it to the white one like image one.
Here's my menu item xml code:
<item android:id="@+id/search_apps"
android:showAsAction="always|collapseActionView"
android:title="search"
android:icon="@drawable/ic_action_search"
android:actionViewClass="android.widget.SearchView"/>
In onCreateOptionsMenu() I am changing the cancel_icon which shows when you type. I am changing the texthint color and removing the search plate bottom blue bar.
Here's the code in case you need it:
// customize android default search view color
int searchTextViewId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
TextView searchTextView = (TextView) searchView.findViewById(searchTextViewId);
searchTextView.setHintTextColor(Color.WHITE);//text-hint color
searchTextView.setTextColor(Color.WHITE);//text color
//change search view icon
int imageViewID = searchView.getContext().getResources().getIdentifier("android:id/search_button", null, null);
ImageView searchButton = (ImageView) searchView.findViewById(imageViewID);
searchButton.setImageResource(R.drawable.ic_action_search);
//change cancel icon
int search_close = searchView.getContext().getResources().getIdentifier("android:id/search_close_btn", null, null);
ImageView cancelIconView = (ImageView) searchView.findViewById(search_close);
cancelIconView.getLayoutParams().width = 70;
cancelIconView.getLayoutParams().height = 70;
cancelIconView.setImageResource(R.drawable.ic_action_cancel);
//search plate
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
View ll_searchPlate = searchView.findViewById(searchPlateId);
ll_searchPlate.setBackgroundColor(Color.parseColor("#52c392"));
As you can see in the java code I am changing the icon for the android:id/search_button because according to searchview source code that is the expanded icon. However it makes no effect. Simple: I am trying to change the search icon that the yellow arrow is pointing to. The reds have been put there purposely due to reasons ;). I am currently stuck and have no way to proceed further.
Search View source code: http://ift.tt/1piAKPX
Thanks man, really helpful.
ReplyDelete