YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← 3 - Setting the Font SOL

Get Embed Code
13 Languages

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

  1. fontFamily is the attribute that
    you would use to set the font for
  2. a TextView.
  3. Since we want the actual
    font to be Sans Serif Light,
  4. sans-serif-light is the value that
    we use for the attribute fontFamily.
  5. To make that a little bit more clear,
    let me show you in Android Studio.
  6. Okay, I'm back here in my
    lovely activity_main.xml and
  7. let's add some more attributes.
  8. I'm going to start with
    the Happy Birthday, Ben TextView, and
  9. the attribute I am adding
    is android:fontFamily.
  10. Okay, and the fontFamily that I wanted
    to use if you remember from the last
  11. slide is sans,
    that's with an s, -serif-light.
  12. And as always, it's nestled
    between two quotation marks.
  13. Now, this is a little bit hard to see,
    but
  14. the preview view has updated to show
    us the thinner, San Serif Light font.
  15. You can see it best if you click on
    something that's not the TextView, and
  16. sort of compare these two look like,
    since this is the old font and
  17. this is the new font.
  18. A couple of things to notice, or
    problems that you might have run into.
  19. These things here are dashes,
    they're not underscores.
  20. So make sure you get
    that absolutely right.
  21. And make sure you spelled
    sans-serif-light completely correct.
  22. For example,
  23. the computer won't recognize
    sans_serif_light with underscores.
  24. You can see here it has
    reverted back to the old font.
  25. Also note, that when you hover over
    the text, you might get this message.
  26. Attribute fontFamily is only used in API
    level 16 and higher, current min is 15.
  27. If you remember back to when we made the
    project, we set the minimum SDK to 15,
  28. or Ice Cream Sandwich.
  29. What this is telling us is, to use this
    attribute, you need one higher version.
  30. This isn't a huge deal but
  31. basically what it means is that on older
    phones you're going to see the old
  32. chunkier font and on newer phones you'll
    actually see the Sans Serif Light font.
  33. Okay, so I'm going to continue on and
    add the attribute to my other TextView.
  34. Let's scroll down.
  35. android:fontFamily.
  36. Okay, and now on the preview screen
    everything looks correct, but
  37. always run it on your phone.
  38. I'm going to hit the green run button.
  39. I'm going to wait a million years.
  40. I'm going to hit the phone,
    going to hit OK.
  41. All right, and when you load it up
    on your phone, you should be able
  42. to see that you have a little bit
    of a thinner Sans Serif Light font.
  43. Excellent work, two down,
    three more to go.