MaterialThemeOverlay

public class MaterialThemeOverlay
extends Object

java.lang.Object
   ↳ com.google.android.material.theme.overlay.MaterialThemeOverlay


Utility to apply a theme overlay to any Context. The theme overlay is read from an attribute in the style. This is useful to override theme attributes only for the specific view.

The intended use is in a custom view constructor.

public MyCustomView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
     super(wrap(context, attrs, defStyleAttr, DEF_STYLE_RES), attrs, defStyleAttr);
 }
 

Summary

Public methods

static Context wrap(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Uses the materialThemeOverlay attribute to create a themed context.

Inherited methods

Public methods

wrap

public static Context wrap (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Uses the materialThemeOverlay attribute to create a themed context. This allows us to use MaterialThemeOverlay with a default style, and gives us some protection against losing our ThemeOverlay by clients who set android:theme or app:theme. If android:theme or app:theme is specified by the client, any attributes defined there will take precedence over attributes defined in materialThemeOverlay.

Parameters
context Context

attrs AttributeSet

defStyleAttr int

defStyleRes int

Returns
Context