The default SearchView
has a search icon in the search hint when it is expanded. I want to remove this icon from the hint.
So I saw this answer on SO. It gives the following solution in onCreate()
:
int magId = getResources().getIdentifier("android:id/search_mag_icon", null, null);
ImageView magImage = (ImageView) searchView.findViewById(magId);
magImage.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
Looking at the xml code of Android's search_view.xml
here, this solution does make complete sense, but I am getting a NullPointerException
at te 6th line in the following snippet:
SearchView searchView = (SearchView) findViewById(R.id.searchActivity_searchView);
int magId = getResources().getIdentifier("android:id/search_mag_icon", null, null);
Log.i(TAG, "magId > "+ magId);
ImageView magImage = (ImageView) searchView.findViewById(magId);
Log.i(TAG, "magImage > "+ magImage);
magImage.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
and before the exception, it prints:
08-07 14:13:15.740: I/SearchActivity(2548): magId > 16909188
08-07 14:13:15.740: I/SearchActivity(2548): magImage > null
So what should I do about this?