English 字幕

← Show Selectors

埋め込みコードを取得する
7言語

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

  1. So here you can see my
    button_custom.xml file.
  2. Now you'll notice I put
    it in res drawable and
  3. I just called it button_custom.xml file.
  4. On it I have my selector,
  5. and my selector uses
    the Standroid Android naming scheme.
  6. And within my selector,
    I then have four items.
  7. These items are for signin_pressed
    where state_pressed is true,
  8. signin_focus drawable when stay_focused
    is true, signin_disabled drawable
  9. when enabled is false, and then just
    the normal drawable for everything else.
  10. It's good practice to put your normal
    drawable at the bottom of the list.
  11. So remember state_pressed is true, will
    give you your signin_pressed graphic,
  12. state_focused is true,
    will give you your signin_focus.
  13. The slightly different one
    is when it's disabled and
  14. you want that ghosted image
    that we saw earlier on.
  15. And that's where
    state_enabled equals false,
  16. there's no state_disabled equals true.
  17. Just watch out for that one.
  18. And then of course like I said,
    your normal one is last.
  19. Now let's take a look at how that
    changes my button definition
  20. within my main activity.
  21. So here's my activity main layout,
    and you can see the button here.
  22. First of all notice that I've just
    change my button from being the sign in
  23. button to just a standard button.
  24. So then the standard button,
    if you look at the background setting,
  25. I've set it to drawable/button_custom,
    so
  26. that's telling the system
    to use button_custom.xml.
  27. If you have named your
    xml file something else,
  28. just make sure that you
    use the drawable here.
  29. I've also made a couple
    of other changes.
  30. Buttons in Android always default so
    that their text is all in capitals.
  31. But we wanted to have a sign
    in with capital S, capital I.
  32. So I change it so
    that text all caps is false and
  33. then my Android text sign
    in will work properly.
  34. I get capital S, capital I.
  35. You could also take that text and
    load it into a string resource, but
  36. I've just hardcoded it here,
    just for brevity.
  37. You can also take that string and
    load it into a string resource, but
  38. I've just left it in here, for brevity.
  39. Finally, because we've changed
    our sign in button to a button so
  40. that we can customize it, we have to
    refactor our a code a little bit.
  41. So let's go and take a look at
    the changes on the main activity.
  42. It's pretty straight forward.
  43. Earlier I had a sign in button
    called M sign in button.
  44. I'm just changing that to be a button.
  45. Then when I'm creating the click
    handler, I just cast the fine view by ID
  46. sign in button to a button
    instead of a sign in button, and
  47. then nothing else changes.
  48. Let's take a look at what the app would
    look like now with a nice Google sign-in
  49. button, instead of the red branded
    button that you saw earlier.
  50. And here, you can see the same app.
  51. I've just laid out
    the buttons differently,
  52. I laid them out vertically
    instead of horizontally.
  53. But, now you can see I have this
    Sign In button instead of the red
  54. Google Plus Sign In button.
  55. And when I touch that,
    I Sign In as before.
  56. As you can see I'm signed into my
    app and I still have to sign out and
  57. revoke access button similar
    to what we had earlier on.
  58. So that's just what the new customized
    Sign In button looks like and
  59. that's more in line with
    the web sign in etc.
  60. etc.
    And it adheres
  61. to the sign in guidelines that
    we saw in the earlier videos.