25

I am trying to use the toolbar widget in android 21 with a custom style but I can't get rid off this error : Failed to find style 'toolbarStyle' in current theme.

Here is my layout xml file :

 <android.support.v7.widget.Toolbar
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/patient_toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:theme="@style/AppTheme.Patient" />

Here is the Patient theme :

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
</style>

<style name="AppTheme.Patient" parent="AppTheme">
    <item name="colorPrimary">@color/patient_primary</item>
    <item name="colorPrimaryDark">@color/patient_primary_dark</item>
    <item name="colorAccent">@color/patient_accent</item>
    <item name="toolbarStyle"></item> <!-- what values to put here -->
</style>

I also tried to add toolbarStyle in item in my theme but I don't know the possible values. Am I missing something?

Dimitri
  • 8,122
  • 19
  • 71
  • 128

2 Answers2

33

I had the same problem event though my xml was correct. The solution was to: Set AppCompat theme in the Theme Select Checkbox, see pic. enter image description here

David Aleksanyan
  • 2,953
  • 4
  • 29
  • 39
  • 1
    My guess is that you have to install Android Support libs in SDK Manager – David Aleksanyan Jun 15 '16 at 05:33
  • @Riten, you can choose "Project Themes" – Cedriga Jan 08 '17 at 16:50
  • The above mentioned problem also raised for me. And you solution worked . Thank you @DavidA – Ever Think Oct 06 '17 at 08:21
  • 1
    If you're like me, you may have been missing the `tools:context` tag in your root node which helps the preview pick up the right theme. See https://stackoverflow.com/questions/11078487/whats-toolscontext-in-android-layout-files – loeschg Sep 06 '18 at 16:39
22

You can use the style Widget.AppCompat.Toolbar.

<!-- Toolbar styles -->
    <item name="toolbarStyle">@style/Widget.AppCompat.Toolbar</item>
Hardian
  • 1,922
  • 22
  • 23
  • Additionally, You can use the @android:style for any style that you're basing your theme from @style/Widget.AppCompat.Toolbar – OYRM Nov 16 '15 at 01:23