SearchView text color in ActionBar using ActionBarSherlock

I want to change the color of the text in an ActionBarSherlock SearchView , so I found this in StackOverflow:

 AutoCompleteTextView searchText = (AutoCompleteTextView) searchView.findViewById(R.id.abs__search_src_text); searchText.setHintTextColor(getResources().getColor(R.color.white)); searchText.setTextColor(getResources().getColor(R.color.white)); 

But the problem is that searchText always null. I also tried using search_src_text (no abs__ ) - again, searchText is null .

I use Sherlock for my ActionBar (with a custom view for the action bar), but I also want to change the color of the text in the search box.

Anything I wonโ€™t get?

+4
source share
2 answers

Modify and apply your styles as follows:

  • Overwrite SearchViewStyle , which defines the appropriate style.

     <style name="SearchViewStyle" parent="Widget.Sherlock.Light.SearchAutoCompleteTextView"> <item name="android:textColor">myTextColor</item> </style> 
  • Add this style definition to your application theme.

     <style name="CustomTheme" parent="Theme.Sherlock.Light"> ... <item name="searchAutoCompleteTextView">@style/SearchViewStyle</item> ... </style> 
  • Apply this theme in the manifest ( android:theme="CustomTheme" ).

Hope this helps ... Greetings!

ps find SearchViewStyle in the ABS style definitions (XML files). This way you can follow the available styles using Ctrl + click on definitions.

+7
source

work differently for me

 @Override public boolean onCreateOptionsMenu(Menu menu) { searchView = new SearchView(getSupportActionBar().getThemedContext()); AutoCompleteTextView searchText = (AutoCompleteTextView) searchView.findViewById(R.id.abs__search_src_text); searchText.setTextColor(Color.BLACK); ..................... } 
0
source

Source: https://habr.com/ru/post/1484459/


All Articles