Simplified searchview modification code

This commit is contained in:
Denis 2015-02-05 16:27:25 +02:00
parent d3fc0fedda
commit fac9108084

View file

@ -183,19 +183,15 @@ public class FavoritesActivity extends TabActivity {
//styling search hint icon and text //styling search hint icon and text
SearchView.SearchAutoComplete searchEdit = (SearchView.SearchAutoComplete) searchView.findViewById(R.id.search_src_text); SearchView.SearchAutoComplete searchEdit = (SearchView.SearchAutoComplete) searchView.findViewById(R.id.search_src_text);
searchEdit.setTextColor(activity.getResources().getColor(R.color.color_white)); searchEdit.setTextColor(activity.getResources().getColor(R.color.color_white));
Class<?> clazz = Class.forName("android.widget.SearchView$SearchAutoComplete");
SpannableStringBuilder stopHint = new SpannableStringBuilder(" "); SpannableStringBuilder stopHint = new SpannableStringBuilder(" ");
Method textSizeMethod = clazz.getMethod("getTextSize"); Float rawTextSize = searchEdit.getTextSize();
Float rawTextSize = (Float)textSizeMethod.invoke(searchEdit);
int textSize = (int) (rawTextSize * 1.25); int textSize = (int) (rawTextSize * 1.25);
//setting icon as spannable //setting icon as spannable
Drawable searchIcon = activity.getResources().getDrawable(R.drawable.ic_action_search_dark); Drawable searchIcon = activity.getResources().getDrawable(R.drawable.ic_action_search_dark);
searchIcon.setBounds(0,0, textSize, textSize); searchIcon.setBounds(0,0, textSize, textSize);
stopHint.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); stopHint.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Method setHintMethod = clazz.getMethod("setHint", CharSequence.class); searchEdit.setHint(stopHint);
setHintMethod.invoke(searchEdit, stopHint);
} catch (Exception e) { } catch (Exception e) {
} }