Android Native Super Toolbar on Steroids
https://www.viralandroid.com/2020/03/android-native-super-toolbar-on-steroids.html
Android Native Super Toolbar on Steroids
Download From GitHub
Download complete project source code from GitHub
Summary
- Animate the toolbar elevation when scrolling
- Center horizontal the toolbar title
- Use light title font
Also, it has been written 100% in Kotlin. ❤️
Download
This library is available in jitpack, so you need to add this repository to your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency:
dependencies {
implementation 'com.github.andrefrsousa:SuperToolbar:1.2.0'
}
Sample Project
We have a sample project in Kotlin that demonstrates the lib usages here.
Usage
It is recommended to check the sample project to get a complete understanding of all the features offered by the library.
In order to show the toolbar elevation you just need to call:
In order to show the toolbar elevation you just need to call:
fun setElevationVisibility(show: Boolean)
If what to have the same effect found in Google Messages app for example, you to add a scroll listener to your RecyclerView or ScrollView. Like this:
myRecyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
toolbar.setElevationVisibility(recyclerView.canScrollVertically(-1))
}
})
Customization
You can costumize your toolber using the following attributes:
// The duration of the elevation animation. By default is 250 miliseconds.
<attr name="superToolbar_animationDuration" format="integer"/>
// If you want to show the toolbar elevation when created. By default is false.
<attr name="superToolbar_showElevationAtStart" format="boolean"/>
// Center the toolbar title. By default is false.
<attr name="superToolbar_centerTitle" format="boolean"/>
// Use a light font as the toolbar title. Default is false.
<attr name="superToolbar_useLightFont" format="boolean"/>
Download complete project source code from GitHub