Change Action Bar onPressed color

后端 未结 2 1502
不知归路
不知归路 2020-12-15 07:09

I cannot figure out how to change the action bar items \"onPressed\" color on Android. I\'m not talking about the action bar background color but about the blue over state.

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-15 08:07

    To set the background for app icon together with the homeAsUpIndicator (there is a common background for these two icons) you have to set android:actionBarItemBackground item in the theme. The theme has to contain something like this (I assume that you use ActionBarSherlock):

    
    

    Where the drawable drawable/my_background.xml would be a StaleListDrawable, containing something like this:

    
    
        
        
    
    

    To disable the background completely, you can set a transparent background, or value @null in the theme might also work.

    The theme item android:actionBarItemBackground sets the background for app icon and homeAsUpIndicator. But it also sets the default background for menu items, overflow icon and background for title. These backgrounds can be overridden.

    Menu items

    To change the menu item background set a proper (android:)actionButtonStyle in the theme like this:

    
    

    And MyActionButtonStyle will contain something like this:

    
    

    Overflow icon

    And finally, to change the overflow icon background set a properandroid:actionOverflowButtonStyle in the theme like this:

    
    

    And MyOverflowButtonStyle will contain something like this:

    
    

提交回复
热议问题