0

I'm a building an activity that loads a specific theme at runtime :

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (shouldLoadLight()) {
        setTheme(R.style.ThemeLight);
    } else {
        setTheme(R.style.ThemeDark);
    }
    super.onCreate(savedInstanceState);

    ...
}

With the Light theme, the Toolbar is white and content is on white background. With the Dark theme, the Toolbar is dark grey and content is on white background too. (like with Light.DarkActionBar old themes)

I need to apply a custom Theme to the toolbar in order to have good touch feedback colors but, as the activity theme is dynamic, I can't set it in my layout XML.

Here what i have tried so far :

theme.xml

<resources>
    <!-- LIGHT -->
    <style name="ThemeLight" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- here, i want grey ripple, it's provided by the light theme already -->
    </style>

    <!-- DARK -->
    <style name="ThemeDark" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- here, i want white ripple, like with the Dark.ActionBar theme -->
        <item name="toolbarStyle">@style/ToolbarDark</item> <!-- not working -->
        <item name="actionbarTheme">@style/ToolbarDark</item> <!-- not working -->
    </style>

    <style name="ToolbarDark" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
        <!-- here, i want white ripple, like with the Dark.ActionBar theme -->
    </style>
</resources>

Any idea of how to achieve such toolbar styling from theme.xml and not from android:theme= xml attribute in layouts ?

Thank you very much, Pierre.

pdegand59
  • 12,776
  • 8
  • 51
  • 58
  • Try applying styles to your toolbar also. like Light.DarkActionBar – Harin Jun 15 '15 at 13:40
  • Directly in the layout's XML ? I can't do this because the global theme is dynamic and therefor, sometime i want Light.DarkActionBar on the Toolbar, some time i just want Light... :s – pdegand59 Jun 15 '15 at 13:47

1 Answers1

0

See Answer of LordRaydenMK in this question

Here you can also have theme attribute for toolbar while using Appcompat Activity.

<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>

Hope it will help.

Community
  • 1
  • 1
Harin
  • 2,413
  • 3
  • 15
  • 30
  • I though `theme` attr is supposed to be deprecated ? I hade some troubles when using `theme` attr and AppCompatDialog with overriden theme. http://developer.android.com/reference/android/support/v7/appcompat/R.attr.html#theme – pdegand59 Jun 16 '15 at 08:59