English subtitles

← From ActionBar to Toolbar

Get Embed Code
4 Languages

Showing Revision 3 created 05/25/2016 by Udacity Robot.

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