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

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

    The cleanest way I found to do this is create a child of 'ThemeOverlay.AppCompat.Dark.ActionBar'. In the example, I set the Toolbar's background color to RED and text's color to BLUE.

    <style name="MyToolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
        <item name="android:background">#FF0000</item>
        <item name="android:textColorPrimary">#0000FF</item>
    </style>
    

    You can then apply your theme to the toolbar:

    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        app:theme="@style/MyToolbar"
        android:minHeight="?attr/actionBarSize"/>
    
    0 讨论(0)
提交回复
热议问题