Wednesday, 9 November 2016

Changing Text Color in Search View

Hello Every one, i was trying to Build an Application and faced a problem in Changing Text Color of a text In Android Native Search View
Well It Was very Simple
 I used Search View in my menu Here is the Sample Code;

@Overridepublic void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    inflater.inflate(R.menu.menu_sort, menu);
    final MenuItem item = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
    searchView.setOnQueryTextListener(this);
    changeSearchViewTextColor(searchView);
}

public static void changeSearchViewTextColor(View view) {


    if (view != null) {

        if (view instanceof TextView) {

            ((TextView) view).setTextColor(Color.WHITE);//Any colour 

            ((TextView) view).setHintTextColor(Color.WHITE);//Any Colour

            ((TextView) view).setCursorVisible(true);

            return;

        } else if (view instanceof ViewGroup) {

            ViewGroup viewGroup = (ViewGroup) view;

            for (int i = 0; i < viewGroup.getChildCount(); i++) {

                changeSearchViewTextColor(viewGroup.getChildAt(i));

            }

        }

    }

}
Just Follow this Step and you will Achieve What you want

No comments:

Post a Comment