Toolbar Search Suggestions Theming

后端 未结 3 1460
太阳男子
太阳男子 2021-02-04 12:29

I’m trying to change search suggestions to “light theme”. I’m using appcompat-v7:22.2.0 library and read about new feature for customizing search view widget (android.support.v

3条回答
  •  庸人自扰
    2021-02-04 13:08

    I know I'm late, but I think it will be helpful for those, who are still searching for this issue. Suggested solution works if use the Toolbar. First you need to override theme of Toolbar in your styles like belov:

    
    
        
    

    I used Dark theme, but I thinkg with Light this solution also will work. As you can see, I had overridden searchViewStyle of Toolbar's theme and suggestionRowLayout of SearchView, where I put my own layout:

    
    
    
    
    
    
        
        
    
        
    
        
    
    
        
        
    
        
        
    
    
    

    This layout I took from original theme and added some changes to it to get what I need.

    NOTE: Unfortunately I didn't find the way how to change the standard recent icon, so I left it, because it was not critical for me.

    So, to change the background color of the suggestion item, just add it to root RelativeLayout - in my case I changed it to white. You can put you own color. I checked that for suggestions use only ImageView with id @android:id/icon1 and TextView with id @android:id/text1 so I added changes to these two. Because of in Dark theme default recent icon is white, I added android:tint="@color/black". TextView you can configure, like you want.

    And the latest thing we need is to apply theme to our Toolbar:

    
    

    Here is a result of what I got:

提交回复
热议问题