How to customize the “up” button when the searchView is being expanded?

前端 未结 3 1766
旧巷少年郎
旧巷少年郎 2021-02-20 03:00

Background

My app has the ability to search for items (which are other apps) using the SearchView on the ActionBar.

The app uses the support library of Google,

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-20 03:58

    How can I fix this issue?

    I created a utility class for this (and other) problems. Get it here:

    https://gist.github.com/consp1racy/96958a1dedf5a99d4ca5

    Part 1: Call the following method in your Activity.onCreate(Bundle):

    ToolbarUtils.fixToolbar(mToolbar);
    

    Part 2: The code uses value android:colorControlNormal from the Toolbar "theme" you specified in the layout. If you use support library and defined only colorControlNormal you need to add the following line after it:

    ?attr/colorControlNormal
    

    What is the cause of this issue?

    After a lot of thought and experiments it seems that the arrow uses the original bitmap, which is white, without any coloring, which is wrong.

    Note: The menu overflow icon also reads the android:colorControlNormal so now it will display correct color as well.

    EDIT: Prerequisites:

    Your Toolbar should have attributes similar to the following

    
    @style/ThemeOverlay.MyApp.ActionBar
    
    @style/ThemeOverlay.AppCompat.Light
    
    @color/material_deep_orange_500
    

    Then the toolbar theme should look something like this

    
    
    

提交回复
热议问题