Skip to content

Instantly share code, notes, and snippets.

View andrefrsousa's full-sized avatar
🏠
Working from home

André Sousa andrefrsousa

🏠
Working from home
View GitHub Profile
@andrefrsousa
andrefrsousa / toolbar_new_font.xml
Created October 28, 2018 14:54
Toolbar with new font
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fontFamily="sans-serif"
@andrefrsousa
andrefrsousa / toolbar_center_title.xml
Last active October 28, 2018 15:24
Toolbar with center title
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@andrefrsousa
andrefrsousa / recycler_view_toolbar_elevation.kt
Created October 28, 2018 14:33
Show toolbar elevation using a RecyclerView
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
toolbar.setElevationVisibility()
if (recyclerView.canScrollVertically(-1)) {
ViewCompat.animate(this).translationZ(toolbarElevation).run {
interpolator = DecelerateInterpolator()
duration = animationDuration
start()
@andrefrsousa
andrefrsousa / nested_scroll_view_toolbar_elevation.kt
Last active October 28, 2018 14:34
Show toolbar elevation using a NestedScrollView
scrollView.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { _, _, scrollY, _, _ ->
if (toolbar == null) {
return@OnScrollChangeListener
}
if (scrollY > 0) {
ViewCompat.animate(this).translationZ(toolbarElevation).run {
interpolator = DecelerateInterpolator()
duration = animationDuration
start()