How do I style appcompat-v7 Toolbar like Theme.AppCompat.Light.DarkActionBar?

后端 未结 7 1542
猫巷女王i
猫巷女王i 2020-11-30 16:46

I\'m trying to recreate the look of Theme.AppCompat.Light.DarkActionBar with the new support library Toolbar.

If I choose Theme.AppCompat.Light

7条回答
  •  误落风尘
    2020-11-30 17:24

    Ok after having sunk way to much time into this problem this is the way I managed to get the appearance I was hoping for. I'm making it a separate answer so I can get everything in one place.

    It's a combination of factors.

    Firstly, don't try to get the toolbars to play nice through just themes. It seems to be impossible.

    So apply themes explicitly to your Toolbars like in oRRs answer

    layout/toolbar.xml

    
    
    

    However this is the magic sauce. In order to actually get the background colors I was hoping for you have to override the background attribute in your Toolbar themes

    values/styles.xml:

    
    
    
    
    

    then just include your toolbar layout in your other layouts

    
    

    and you're good to go.

    Hope this helps someone else so you don't have to spend as much time on this as I have.

    (if anyone can figure out how to make this work using just themes, ie not having to apply the themes explicitly in the layout files I'll gladly support their answer instead)

    EDIT:

    So apparently posting a more complete answer was a downvote magnet so I'll just accept the imcomplete answer above but leave this answer here in case someone actually needs it. Feel free to keep downvoting if it makes you happy though.

提交回复
热议问题