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

后端 未结 7 1506
猫巷女王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:28

    The recommended way to style the Toolbar for a Light.DarkActionBar clone would be to use Theme.AppCompat.Light.DarkActionbar as parent/app theme and add the following attributes to the style to hide the default ActionBar:

    
    

    Then use the following as your Toolbar:

    
    
        
    
    

    For further modifications, you would create styles extending ThemeOverlay.AppCompat.Dark.ActionBar and ThemeOverlay.AppCompat.Light replacing the ones within AppBarLayout->android:theme and Toolbar->app:popupTheme. Also note that this will pick up your ?attr/colorPrimary if you have set it in your main style so you might get a different background color.

    You will find a good example of this is in the current project template with an Empty Activity of Android Studio (1.4+).

提交回复
热议问题