2017-02-08 4 views
0

Когда я добавляю SearchView на панель инструментов, он показывает текст и значки черным, а не белым. Когда я добавляю его в ActionBar, я получил его белым. Моя панель устанавливается следующим образомСопровождение материала SearchView на панели инструментов

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/LightApplicationTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:contentInsetEnd="0dp" 
     app:contentInsetLeft="0dp" 
     app:contentInsetRight="0dp" 
     app:contentInsetStart="0dp" 
     app:contentInsetStartWithNavigation="0dp" 
     app:contentInsetEndWithActions="0dp" 
     app:theme="@style/LightApplicationTheme.AppBarOverlay" 
     app:popupTheme="@style/LightApplicationTheme.PopupOverlay"/> 

</android.support.design.widget.AppBarLayout> 

Моя тема приложение расширяет Theme.AppCompat.Light.DarkActionBar и стилей у меня есть следующие;

<style name="LightApplicationTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"> 
</style> 

<style name="LightApplicationTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"> 
</style> 

Я знаю, что могу добавить <item name="searchViewStyle">@style/SearchViewStyle</item> в стиле приложений (не стиль панели инструментов), а затем в SearchViewStyle я могу установить следующее;

<style name="SearchViewStyle" parent="Widget.AppCompat.SearchView"> 
<!-- Background for the search query section (e.g. EditText) --> 
<!-- <item name="queryBackground">@android:color/black</item> --> 
<!-- Background for the actions section (e.g. voice, submit) --> 
<!-- <item name="submitBackground">...</item> --> 
<!-- Close button icon --> 
<!-- <item name="closeIcon">...</item> --> 
<!-- Search button icon --> 
<!-- <item name="searchIcon">...</item> --> 
<!-- Go/commit button icon --> 
<!-- <item name="goIcon">...</item> --> 
<!-- Voice search button icon --> 
<!-- <item name="voiceIcon">...</item> --> 
<!-- Commit icon shown in the query suggestion row --> 
<!-- <item name="commitIcon">...</item> --> 
<!-- Layout for query suggestion rows --> 
<!-- <item name="suggestionRowLayout">...</item> --> 
</style> 

, но я понятия не имею, как изменить цвет текста и цвет выпадающего списка. Любые советы?

ответ

0

Ну, я сделал это, используя какой-то (грязный) код. Вот он;

mSearchView = new SearchView(this); 
.... 
applyColorToAllViews(mSearchView, Color.WHITE); 


И вот функция, которая делает это;

private void applyColorToAllViews(ViewGroup group, @ColorInt int tintColor) 
{ 
    int count = group.getChildCount(); 
    for (int i = 0; i < count; ++i) 
    { 
     View v = group.getChildAt(i); 
     if (v instanceof ViewGroup) 
     { 
      applyColorToAllViews((ViewGroup)v, tintColor); 
     } 
     else if (v instanceof ImageView) 
     { 
      ImageView iv = (ImageView)v; 
      Drawable drawable = iv.getDrawable(); 
      if (drawable != null) 
      { 
       DrawableCompat.setTint(drawable, tintColor); 
       iv.setImageDrawable(drawable); 
      } 
     } 
     else if (v instanceof TextView) 
     { 
      TextView tv = (TextView)v; 
      tv.setTextColor(tintColor); 
      tv.setHintTextColor(0x80000000 | (tintColor & 0xFFFFFF)); 
     } 
    } 
}