Android Studio: Chipmunk | 2021.2.1
A custom accordion/expandable view using the oficial guidelines defiend in: Creating a View Class
Also, we are using the Kotlin DSL approach to register expand/collapse listeners.
For more details, see
BaseAccordionView.setListenersclass implementation that use Kotlin Function literals with receiver
You can use the accordion view in a .xml layout file:
<com.example.mywidgets.accordion.view.AccordionView
android:id="@+id/accordionView"
style="@style/body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:visibility="visible"
app:animate="false"
app:animateArrow="false"
app:expanded="true"
app:displayDivider="true"
app:collapseOthers="true"
app:headerText="Expandable">
<!-- Add any view here to put inside of "content" ViewGroup -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Content text"
android:gravity="center"/>
<Button
android:id="@+id/btnAccordion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Accordion Button"
android:gravity="center"
/>
</com.example.mywidgets.accordion.AccordionView>Or instantiate this view programmatically:
var accordionItem = AccordionView(context)
// Define the title of the accordion
accordionItem.setHeaderText("Expandable title")
// Add views programatically to this accordion
accordionItem.addViewsToContent([view1, view2])- Add unit tests
- Add integration/UI tests to this custom view. Maybe create a example fragment and test inside of it ?
- Add an
appmodule with an example Android app to test this view.