Created
February 24, 2015 22:01
-
-
Save mauriciogior/7744521aaba3b15fc254 to your computer and use it in GitHub Desktop.
Change cursor in search view widget for AppCompat v21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We need to use reflection... | |
// yes, I know, it sucks! | |
@Override | |
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { | |
super.onCreateOptionsMenu(menu, inflater); | |
inflater.inflate(R.menu.menu_with_search, menu); | |
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView(); | |
final EditText editTextView = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); | |
try { | |
Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes"); | |
mCursorDrawableRes.setAccessible(true); | |
mCursorDrawableRes.set(editTextView, 0); // 0: @null (automatic), or any drawable of yours. | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this!