I have a weird problem at my hands. I need to be able to vertically center the hint text of a SearchView widget so that it aligns with the magnifying glass and the close icon.
Here's a snippet of what I have so far:
SearchView sv = (SearchView) view.findViewById(R.id.search);
int id = sv.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
int searchPlate = sv.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
int searchMagIcon = sv.getContext().getResources().getIdentifier("android:id/search_mag_icon", null, null);
ImageView magIcon = (ImageView) sv.findViewById(searchMagIcon); View searchPlateView = sv.findViewById(searchPlate);
EditText searchText = (EditText) sv.findViewById(id); searchText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
//searchText.setHint("Some test hint text here");
searchPlateView.setBackgroundColor(Color.WHITE);
searchText.setHintTextColor(Color.parseColor("#D8D8D8"));
sv.setIconified(false);
sv.clearFocus();
In the commented out line, I've found that this aligns perfectly with the close icon to the right, however, this gets rid of the magnifying glass icon. I've tried using reflection, outlined in this article http://nlopez.io/how-to-style-the-actionbar-searchview-programmatically/
However, this moved both the hint text and the magnifying glass and did some other weird stuff. From my observations, it seems that the magnifying glass is actually tied to the hint text, although in the above code (which I've scoured from the android code base) it seems that the magnifying glass is its own thing? I have tried to play around with it, such as creating an ImageView from the magnifying glass id. But nothing came out of it.