1919import com .google .android .material .R ;
2020
2121import static androidx .annotation .RestrictTo .Scope .LIBRARY_GROUP ;
22+ import static com .google .android .material .theme .overlay .MaterialThemeOverlay .wrap ;
2223
2324import android .animation .ValueAnimator ;
2425import android .content .Context ;
111112 */
112113public class CollapsingToolbarLayout extends FrameLayout {
113114
115+ private static final int DEF_STYLE_RES = R .style .Widget_Design_CollapsingToolbar ;
114116 private static final int DEFAULT_SCRIM_ANIMATION_DURATION = 600 ;
115117
116118 private boolean refreshToolbar = true ;
@@ -152,7 +154,9 @@ public CollapsingToolbarLayout(@NonNull Context context, @Nullable AttributeSet
152154 }
153155
154156 public CollapsingToolbarLayout (@ NonNull Context context , @ Nullable AttributeSet attrs , int defStyleAttr ) {
155- super (context , attrs , defStyleAttr );
157+ super (wrap (context , attrs , defStyleAttr , DEF_STYLE_RES ), attrs , defStyleAttr );
158+ // Ensure we are using the correctly themed context rather than the context that was passed in.
159+ context = getContext ();
156160
157161 collapsingTextHelper = new CollapsingTextHelper (this );
158162 collapsingTextHelper .setTextSizeInterpolator (AnimationUtils .DECELERATE_INTERPOLATOR );
@@ -163,7 +167,7 @@ public CollapsingToolbarLayout(@NonNull Context context, @Nullable AttributeSet
163167 attrs ,
164168 R .styleable .CollapsingToolbarLayout ,
165169 defStyleAttr ,
166- R . style . Widget_Design_CollapsingToolbar );
170+ DEF_STYLE_RES );
167171
168172 collapsingTextHelper .setExpandedTextGravity (
169173 a .getInt (
0 commit comments