Stay organized with collections
Save and categorize content based on your preferences.
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 |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
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 |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# MaterialThemeOverlay\n\nSummary: [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \n\nMaterialThemeOverlay\n====================\n\n\n`\npublic\n\n\nclass\nMaterialThemeOverlay\n`\n\n\n`\n\nextends Object\n\n\n`\n\n`\n\n\n`\n\n|---|----------------------------------------------------------------|\n| java.lang.Object ||\n| ↳ | com.google.android.material.theme.overlay.MaterialThemeOverlay |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nUtility to apply a theme overlay to any [Context](/reference/android/content/Context). The theme overlay is\nread from an attribute in the style. This is useful to override theme attributes only for the\nspecific view.\n\nThe intended use is in a custom view constructor.\n\n public MyCustomView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {\n super(wrap(context, attrs, defStyleAttr, DEF_STYLE_RES), attrs, defStyleAttr);\n }\n \n\u003cbr /\u003e\n\nSummary\n-------\n\n| ### Public methods ||\n|-------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` static Context` | ` `[wrap](/reference/com/google/android/material/theme/overlay/MaterialThemeOverlay#wrap(android.content.Context,%20android.util.AttributeSet,%20int,%20int))`(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) ` Uses the materialThemeOverlay attribute to create a themed context. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From class ` java.lang.Object ` |-------------------|-------------------------------| | ` Object` | ` clone() ` | | ` boolean` | ` equals(Object arg0) ` | | ` void` | ` finalize() ` | | ` final Class\u003c?\u003e` | ` getClass() ` | | ` int` | ` hashCode() ` | | ` final void` | ` notify() ` | | ` final void` | ` notifyAll() ` | | ` String` | ` toString() ` | | ` final void` | ` wait(long arg0, int arg1) ` | | ` final void` | ` wait(long arg0) ` | | ` final void` | ` wait() ` | ||\n\nPublic methods\n--------------\n\n### wrap\n\n```\npublic static Context wrap (Context context, \n AttributeSet attrs, \n int defStyleAttr, \n int defStyleRes)\n```\n\nUses the materialThemeOverlay attribute to create a themed context. This allows us to use\nMaterialThemeOverlay with a default style, and gives us some protection against losing our\nThemeOverlay by clients who set android:theme or app:theme. If android:theme or app:theme is\nspecified by the client, any attributes defined there will take precedence over attributes\ndefined in materialThemeOverlay.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------------|-----------------------|\n| `context` | `Context` \u003cbr /\u003e |\n| `attrs` | `AttributeSet` \u003cbr /\u003e |\n| `defStyleAttr` | `int` \u003cbr /\u003e |\n| `defStyleRes` | `int` \u003cbr /\u003e |\n\n| Returns ||\n|-----------|--------|\n| `Context` | \u003cbr /\u003e |"]]