FloatingActionButtonExpandable
An android library that brings the collapsible card.
Note: The Extended FAB is a Material Design component that adds a descriptive label to the primary action button and can dynamically collapse into a standard icon FAB upon scrolling. You can find this Extended FAB component at https://github.com/material-components/material-components-android/blob/master/docs/components/ExtendedFloatingActionButton.md
Preview
Compatibility
Minimum Android SDK: API level 23
Setup
Step 1. Add the JitPack repository in your root build.gradle at the end of repositories:
allprojects {
repositories {
// Declare other repositories
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency:
dependencies {
implementation "com.github.tuannguyen50:collapsible-card:1.2.1"
}
Usage
Layout XML
Add xmlns:app="http://schemas.android.com/apk/res-auto" as an attribute on the root (parent)
view group tag in your Android XML layout file
<tuanthanhnguyen.collapsiblecard.CollapsibleCard
android:id="@+id/collapsible_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/padding_normal"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:title="@string/collapsible_card_button_start_chat"
app:padding_text_icon="@dimen/padding_text_icon"
app:text_color="@android:color/white"
app:bg_color="@color/bg_collapsible_card"
app:icon="@drawable/ic_message_white_24dp"
app:duration="100"
app:text_size="@dimen/text_size_collapsible_card"
app:typeface="fonts/RobotoSlab-Regular.ttf"
app:padding="@dimen/padding_collapsible_card"
app:expanded="true" />
Kotlin
val collapsibleCard = findViewById<CollapsibleCard>(R.id.collapsible_card)
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
if (dy > 0) {
collapsibleCard.collapse()
} else {
collapsibleCard.expand()
}
}
})
// toggle expand, collapse
collapsibleCard.toggle()
// expand
collapsibleCard.expand()
// collapse
collapsibleCard.collapse()
collapsibleCard.setExpanded(true)
collapsibleCard.setDuration(100L)
collapsibleCard.setTitle("Start Chat")
// drawable, resId, bitmap
collapsibleCard.setIconActionButton(R.drawable.ic_message_white_24dp)
collapsibleCard.setTextColor(ContextCompat.getColor(this, R.color.white))
collapsibleCard.setBackgroundButtonColor(ContextCompat.getColor(this, R.color.bg_collapsible_card))
// padding between the icon and text
collapsibleCard.setPaddingTextIcon(resources.getDimensionPixelSize(R.dimen.padding_collapsible_card_text_icon))
// padding inside the button
collapsibleCard.setPaddingInsideButton(resources.getDimensionPixelSize(R.dimen.padding_collapsible_card))
// pixel
collapsibleCard.setTextSize(resources.getDimensionPixelSize(R.dimen.text_size_collapsible_card).toFloat())
// or
collapsibleCard.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f)
// text style
collapsibleCard.setTypeface(Typeface.BOLD)
// font
val typeface = Typeface.createFromAsset(assets, "fonts/RobotoSlab-Regular.ttf")
collapsibleCard.setTypeface(typeface)
Attributes
| Attribute name | Type | Description |
|---|---|---|
| title | string | The title of the button |
| padding_text_icon | dimension | The padding between the text and icon |
| text_color | color | The color of the text |
| bg_color | color | The background color of the button |
| icon | reference | The icon of the button |
| duration | integer | The length of the expand or collapse animation |
| text_size | dimension | The text size of the button |
| typeface | string | The font path in assets folder |
| padding | dimension | The padding inside the button |
| expanded | boolean | The button is expanded if you set true |
Derivative work notice
This project is a derivative work based on the Google organization's CollapsibleCard.kt Kotlin file on GitHub. This CollapsibleCard.kt Kotlin file is released under the Apache License 2.0.
License
Copyright (C) 2018 Tuan Thanh Nguyen
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
