Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 35  Material Design


Listing 35.10  Laying out a floating action button


<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
[... main content here ...]
<android.support.design.widget.FloatingActionButton
android:id="@+id/floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@drawable/play"/>



This code will place the button over the rest of the content in the bottom right, without interfering with
any of it.


Snackbars


Snackbars are a bit more involved than floating action buttons. They are little interaction components
that appear at the bottom of the screen (Figure 35.12).


Figure 35.12  A snackbar

Free download pdf