Return to Video

Practice Calling Object Methods - Sol

  • 0:00 - 0:03
    Earlier I showed you how to
    create a new textView and
  • 0:03 - 0:05
    then call a method to
    change the text on it.
  • 0:06 - 0:08
    What if I want to change the text size?
  • 0:09 - 0:13
    I can just call textView.setTextSize and
    hit Enter.
  • 0:13 - 0:18
    And then just pick
    a random value like 56.
  • 0:18 - 0:21
    And then I can run it on my device.
  • 0:23 - 0:24
    And this is what it looks like.
  • 0:25 - 0:26
    Wow, that's big.
  • 0:26 - 0:27
    Then I can change
    the text color as well.
  • 0:27 - 0:34
    I can do textView.settextcolor and
    then pass in a color.
  • 0:34 - 0:36
    I showed you the possible
    colors earlier.
  • 0:36 - 0:40
    So let me just pick one like green.
  • 0:40 - 0:43
    When I run this on the device,
    it shows up in neon green.
  • 0:43 - 0:46
    If you look through
    the textView documentation,
  • 0:46 - 0:50
    you may have found other
    methods you can call.
  • 0:50 - 0:53
    For example,
    you can call textView.setMaxLines.
  • 0:53 - 0:58
    This limits the number of the lines that
    the text view shows to only two lines.
  • 0:58 - 1:01
    If the text is longer than that,
    then it just gets cut off.
  • 1:01 - 1:03
    To test this,
    we'll need a really long string here.
  • 1:04 - 1:08
    And, actually, in order to know
    whether this is working properly,
  • 1:08 - 1:10
    I should comment this out first.
  • 1:10 - 1:13
    I'm going to run the app to make sure
    that this string is actually longer than
  • 1:13 - 1:14
    two lines of text.
  • 1:16 - 1:19
    Okay, we verified that it's actually
    two and a half lines of text.
  • 1:20 - 1:24
    Once I uncomment this line of code
    to set the max line limit to 2 then
  • 1:24 - 1:28
    when I run the app then it should
    truncate this to two lines here.
  • 1:29 - 1:31
    And it does, cool.
  • 1:31 - 1:34
    So hopefully you got some good practice
    in with calling methods on an object
  • 1:34 - 1:36
    like textView.
  • 1:36 - 1:39
    It's actually uncommon to
    call a setContentView and
  • 1:39 - 1:42
    then pass in a single view like this.
  • 1:42 - 1:46
    Normally the content view of your
    activity will be a lot more complex.
  • 1:46 - 1:50
    And so that's why we would normally
    leave it as setContentView and
  • 1:50 - 1:53
    then passing in the resource
    ID of an XML layout.
タイトル:
Practice Calling Object Methods - Sol
概説:

more » « less
Video Language:
English
Team:
Udacity
プロジェクト:
UD837 - Android for Beginners
Duration:
01:56

English subtitles

改訂 Compare revisions