3. android.support.design.widget.Snackbar
Just like a Toast
Snackbar.make(rootLayout, "Hello. I am Snackbar!", Snackbar.LENGTH_SHORT)
.setAction("Undo", new View.OnClickListener() {
@Override
public void onClick(View v) {
}
})
.show();
Snackbar
4. CoordinatorLayout
building dependencies between sibling views and allowing easy
scrolling reactions between components
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Place Views Inside -->
</android.support.design.widget.CoordinatorLayout
5. AppBarLayout
a container for Toolbar to make it fit in CoordinatorLayout
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</android.support.design.widget.AppBarLayout>
<!-- Other views -->
</android.support.design.widget.CoordinatorLayout>
6. CoordinatorLayout’s Content
You need to apply
app:layout_behavior="@string/appbar_scrolling_view_behavior"
to the content view inside Coordinator or it will be placed at
the same position as where Toolbar is
8. TabLayout
You could place tabs easily with TabLayout. Support for both
fixed and scrollable. Also works with ViewPager.
<android.support.design.widget.CoordinatorLayout ...>
<android.support.design.widget.AppBarLayout ...>
<android.support.v7.widget.Toolbar .../>
<android.support.design.widget.TabLayout
android:id=“@+id/tabLayout”
android:layout_width="match_parent“ android:layout_height="match_parent" />
</android.support.design.widget.AppBarLayout>
...
</android.support.design.widget.CoordinatorLayout>
10. TabLayout
Parameters:
app:tabMode – fixed (all tabs are shown concurrently)
– scrollable (show a subset of tabs)
app:tabGravity – fill (distribute all available space)
– center (position tabs in the center of
TabLayout)
12. CollapsingToolbarLayout
Simply wrap Toolbar with this layout
<android.support.design.widget.AppBarLayout ...>
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent“ android:layout_height="match_parent“
app:contentScrim=“?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
app:layout_collapseMode=“pin“ .../>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
13. CollapsingToolbarLayout
Toolbar’s background is recommended to be removed
You can place another View inside at the same approach as
FrameLayout. Also with parallax support.
<android.support.design.widget.CollapsingToolbarLayout ...>
<ImageView
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7“
...>
<android.support.v7.widget.Toolbar .../>
</android.support.design.widget.CollapsingToolbarLayout>