带有ActionBarSherlock的ActionBar中SearchView的文本颜色

use*_*513 4 android actionbarsherlock

我想更改ActionBarSherlock中文本的颜色SearchView,所以我在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));    
Run Code Online (Sandbox Code Playgroud)

但问题是searchText总是空.我也试过search_src_text(不abs__) - 再次,searchTextnull.

我使用Sherlock作为我的ActionBar(具有操作栏的自定义视图)但我也希望更改搜索视图的文本颜色.

我得到的任何东西?

Tri*_*mon 7

更改并应用您的样式如下:

  1. 覆盖SearchViewStyle定义相关样式.

    <style name="SearchViewStyle" 
           parent="Widget.Sherlock.Light.SearchAutoCompleteTextView">
        <item name="android:textColor">myTextColor</item>
    </style>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 将此样式定义添加到您的应用主题.

    <style name="CustomTheme" parent="Theme.Sherlock.Light">
        ...
        <item name="searchAutoCompleteTextView">@style/SearchViewStyle</item>
        ...
    </style>
    
    Run Code Online (Sandbox Code Playgroud)
  3. 在你的Manifest(android:theme="CustomTheme")中应用这个主题.

希望这会有所帮助......干杯!

ps搜索SearchViewStyleABS样式定义(XML文件).这样,您可以使用Ctrl +单击定义来跟踪可用的样式.