-
Title:
From ActionBar to Toolbar
-
Description:
-
The Android 5.0 introduced
a new tool bar widget.
-
This generalization of the action bar
pattern, gives you much more control and
-
flexibility.
-
Tool bars of view and your hierarchy
just like any other, making it easier to
-
interweave with the rest of your hues,
animate and react to scroll events.
-
Many Androids apps now have two or
more tool bars.
-
As in this example.
-
Toolbars are made particularly
important, because of the design rule
-
that we aren't supposed to split a
toolbar with another piece of material.
-
This means we often
need multiple toolbars.
-
Fortunately, we have a fully
functional version that has been
-
built as part of the Android
support library.
-
In order to make use of toolbar, we need
to first change our application to use
-
a theme that doesn't add
an action bar on our behalf.
-
I'm going to create a base toolbar
style, that gives it a background color.
-
Toolbars have transparent
backgrounds by default.
-
We'll also make sure that we're
using the light pop up theme.
-
This will be important when
you set the toolbars to
-
the dark theme in our layouts.
-
That we can have a little more light
colored text that will pop against our
-
dark background.
-
I can make all of my
toolbars get this new style,
-
by placing a toolbar
style in the app theme.
-
Then you just add
the toolbar into our layout.
-
Note that I'm setting the size to
be the standard action bar size
-
from the current theme,
using the ?attr notation.
-
And I'm setting the theme to
be the overlay theme for dark.
-
This will nicely style
us with light text.
-
Finally, I can make the toolbar
behave like an action bar.
-
By setting into the activity
using setSupportActionBar.
-
Once it's there, I can apply action bar
styling to it using getSupportActionBar.
-
I could use these functions
to get the icon back, but
-
I want to demonstrate one other
cool thing about toolbar.
-
It contains a view group
that you can customize.
-
This view group is like an even
more simple frame layout.
-
So we could add our logo back
to the toolbar this way.
-
This level of control,
-
becomes useful as we continue
to work towards our new design.