Adding two AppCompat toolbars with different themes

I would like to have two different android.support.v7.widget.Toolbars files in my application, one dark, one light and switch between them when necessary. However, when I install another theme on the second toolbar, it seems to reset the theme on the first toolbar.

Is this a mistake or an alleged behavior?

Toolbar 1:

<android.support.v7.widget.Toolbar xmlns:sothree="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main_toolbar" android:layout_height="?attr/actionBarSize" android:layout_width="match_parent" android:layout_gravity="top" android:background="@drawable/action_bar_background" sothree:theme="@style/ThemeOverlay.AppCompat.ActionBar" sothree:contentInsetStart="0dp"/> 

Toolbar 2:

 <android.support.v7.widget.Toolbar xmlns:sothree="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/clip_toolbar" android:layout_height="?attr/actionBarSize" android:layout_width="match_parent" android:layout_gravity="top" android:background="@android:color/transparent" sothree:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" sothree:popupTheme="@style/ThemeOverlay.AppCompat.Light" sothree:contentInsetStart="0dp"/> 
+5
source share
1 answer

Make ContextThemeWrapper:

 ContextThemeWrapper wrapper = new ContextThemeWrapper(context, R.style.Some_Theme); 

Use the current context to inflate one toolbar and use ContextThemeWrapper to inflate another. Use getLayoutInflater() to get a scam for each context.

0
source

Source: https://habr.com/ru/post/1205465/


All Articles