Stay organized with collections
Save and categorize content based on your preferences.
public
interface
ExpandableWidget
com.google.android.material.expandable.ExpandableWidget
|
Known indirect subclasses
|
A widget that has expanded/collapsed state. When the expanded state changes, an event is
dispatched
so that other widgets may react via a CoordinatorLayout.Behavior
.
Implementations of this interface should create an instance of ExpandableWidgetHelper
and forward all calls to it.
The expanded state can saved across configuration changes by implementing View.onSaveInstanceState()
and View.onRestoreInstanceState(Parcelable)
:
@Override
protected Parcelable onSaveInstanceState() {
Parcelable superState = super.onSaveInstanceState();
ExtendableSavedState state = new ExtendableSavedState(superState);
state.extendableStates.put(
"expandableWidgetHelper", expandableWidgetHelper.onSaveInstanceState());
return state;
}
@Override
protected void onRestoreInstanceState(Parcelable state) {
if (!(state instanceof ExtendableSavedState)) {
super.onRestoreInstanceState(state);
return;
}
ExtendableSavedState ess = (ExtendableSavedState) state;
super.onRestoreInstanceState(ess.getSuperState());
expandableWidgetHelper.onRestoreInstanceState(
ess.extendableStates.get("expandableWidgetHelper"));
}
Summary
Public methods |
abstract
boolean
|
isExpanded()
Returns whether this widget is expanded.
|
abstract
boolean
|
setExpanded(boolean expanded)
Sets the expanded state on this widget.
|
Public methods
setExpanded
public abstract boolean setExpanded (boolean expanded)
Sets the expanded state on this widget.
Implementations should call ExpandableWidgetHelper.setExpanded(boolean)
.
Parameters |
expanded |
boolean |
Returns |
boolean |
true if the expanded state changed as a result of this call.
|
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# ExpandableWidget\n\nSummary: [Methods](#pubmethods) \n\nExpandableWidget\n================\n\n\n`\npublic\n\n\ninterface\nExpandableWidget\n`\n\n\n`\n\n\n`\n\n|---------------------------------------------------------|\n| com.google.android.material.expandable.ExpandableWidget |\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known indirect subclasses [ExpandableTransformationWidget](/reference/com/google/android/material/expandable/ExpandableTransformationWidget), [FloatingActionButton](/reference/com/google/android/material/floatingactionbutton/FloatingActionButton) |--------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------| | [ExpandableTransformationWidget](/reference/com/google/android/material/expandable/ExpandableTransformationWidget) | An ExpandableWidget that visually transforms into another component when expanded. | | [FloatingActionButton](/reference/com/google/android/material/floatingactionbutton/FloatingActionButton) | Floating action buttons are used for a special type of promoted action. | |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nA widget that has expanded/collapsed state. When the expanded state changes, [an event is\ndispatched](/reference/androidx/coordinatorlayout/widget/CoordinatorLayout#dispatchDependentViewsChanged(android.view.View)) so that other widgets may react via a [CoordinatorLayout.Behavior](/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.Behavior).\n\nImplementations of this interface should create an instance of [ExpandableWidgetHelper](/reference/com/google/android/material/expandable/ExpandableWidgetHelper)\nand forward all calls to it.\n\nThe expanded state can saved across configuration changes by implementing [View.onSaveInstanceState()](/reference/android/view/View#onSaveInstanceState()) and [View.onRestoreInstanceState(Parcelable)](/reference/android/view/View#onRestoreInstanceState(android.os.Parcelable)):\n\n\n @Override\n protected Parcelable onSaveInstanceState() {\n Parcelable superState = super.onSaveInstanceState();\n ExtendableSavedState state = new ExtendableSavedState(superState);\n\n state.extendableStates.put(\n \"expandableWidgetHelper\", expandableWidgetHelper.onSaveInstanceState());\n\n return state;\n }\n\n @Override\n protected void onRestoreInstanceState(Parcelable state) {\n if (!(state instanceof ExtendableSavedState)) {\n super.onRestoreInstanceState(state);\n return;\n }\n\n ExtendableSavedState ess = (ExtendableSavedState) state;\n super.onRestoreInstanceState(ess.getSuperState());\n\n expandableWidgetHelper.onRestoreInstanceState(\n ess.extendableStates.get(\"expandableWidgetHelper\"));\n }\n \n\u003cbr /\u003e\n\nSummary\n-------\n\n| ### Public methods ||\n|---------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract boolean` | ` `[isExpanded](/reference/com/google/android/material/expandable/ExpandableWidget#isExpanded())`() ` Returns whether this widget is expanded. |\n| ` abstract boolean` | ` `[setExpanded](/reference/com/google/android/material/expandable/ExpandableWidget#setExpanded(boolean))`(boolean expanded) ` Sets the expanded state on this widget. |\n\nPublic methods\n--------------\n\n### isExpanded\n\n```\npublic abstract boolean isExpanded ()\n```\n\nReturns whether this widget is expanded.\n\nImplementations should call [ExpandableWidgetHelper.isExpanded()](/reference/com/google/android/material/expandable/ExpandableWidgetHelper#isExpanded()).\n\n\u003cbr /\u003e\n\n| Returns ||\n|-----------|--------|\n| `boolean` | \u003cbr /\u003e |\n\n### setExpanded\n\n```\npublic abstract boolean setExpanded (boolean expanded)\n```\n\nSets the expanded state on this widget.\n\nImplementations should call [ExpandableWidgetHelper.setExpanded(boolean)](/reference/com/google/android/material/expandable/ExpandableWidgetHelper#setExpanded(boolean)).\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------|------------------|\n| `expanded` | `boolean` \u003cbr /\u003e |\n\n| Returns ||\n|-----------|---------------------------------------------------------------------|\n| `boolean` | true if the expanded state changed as a result of this call. \u003cbr /\u003e |"]]