1 00:00:00,380 --> 00:00:02,047 Back in the ColorWheel class, 2 00:00:02,047 --> 00:00:05,327 let's change getColor to return an Int instead of a String. 3 00:00:08,762 --> 00:00:12,290 And now we need to convert the string color to an Int. 4 00:00:12,290 --> 00:00:18,640 Right above the return statement, let's add a new val named colorAsInt. 5 00:00:19,870 --> 00:00:26,367 And let's set it equal to Color with a capital C and enter to import it dot. 6 00:00:26,367 --> 00:00:31,505 And then if we start typing parseColor we can see that parseColor 7 00:00:31,505 --> 00:00:36,980 is a method that takes in a colorString and returns an Int. 8 00:00:36,980 --> 00:00:38,052 Just what we're looking for. 9 00:00:38,052 --> 00:00:41,600 The parseColor method is a handy utility method 10 00:00:41,600 --> 00:00:46,110 that takes a hexadecimal string just like what we have up here. 11 00:00:46,110 --> 00:00:50,720 And converts it to an integer representation the Android can understand. 12 00:00:50,720 --> 00:00:54,509 So now instead of returning a randomly selected colorString, 13 00:00:54,509 --> 00:00:58,520 let's pass that random colorString into the parseColor method. 14 00:00:59,580 --> 00:01:03,910 So we'll pass in colors at index randomNumber. 15 00:01:05,830 --> 00:01:10,253 Finally, since we need to be returning integer, let's return our new color as int 16 00:01:10,253 --> 00:01:15,933 variable, And 17 00:01:15,933 --> 00:01:19,051 head back to FunFactsActivity. 18 00:01:19,051 --> 00:01:23,580 Now instead of a string, we're returning an int, and everything looks good. 19 00:01:24,700 --> 00:01:27,830 Now let's run our app and verify it's working as we expect it to. 20 00:01:29,862 --> 00:01:32,040 Okay, moment of truth. 21 00:01:33,210 --> 00:01:37,240 Tap the button, and nice, all sorts of different colors. 22 00:01:38,580 --> 00:01:42,270 There's one more thing I'd like to do here, one last color. 23 00:01:43,610 --> 00:01:47,050 Notice that the color of the button text is black, but 24 00:01:47,050 --> 00:01:49,230 in our mockups, it's matching the background color. 25 00:01:51,190 --> 00:01:53,248 Let's go back to our code and change this. 26 00:01:53,248 --> 00:01:58,020 In our OnClickListener, we already have a color that we want to use and 27 00:01:58,020 --> 00:02:01,510 we already have a variable for our button, showFactButton. 28 00:02:01,510 --> 00:02:04,380 Let's add a new line at the bottom of our OnClickListener and 29 00:02:04,380 --> 00:02:05,390 add a reference to our button. 30 00:02:07,010 --> 00:02:09,070 Then let's assert that it's not null. 31 00:02:10,110 --> 00:02:12,210 And then let's look for the method we need. 32 00:02:12,210 --> 00:02:18,630 Let's type .set and we're looking for text color so let's add textcolor. 33 00:02:18,630 --> 00:02:19,530 And then right here, 34 00:02:19,530 --> 00:02:24,100 we see a method called setTextColor that takes in an Int parameter. 35 00:02:24,100 --> 00:02:24,840 Let's click that one. 36 00:02:26,060 --> 00:02:27,520 Then, let's pass in our color variable. 37 00:02:29,410 --> 00:02:32,110 Cool, but we're not quite done. 38 00:02:32,110 --> 00:02:36,200 We're only changing the text color after the button has been tapped. 39 00:02:36,200 --> 00:02:39,320 If the button hasn't been tapped, we'll still see black text. 40 00:02:40,400 --> 00:02:43,570 We should change our button's default text color to match the default 41 00:02:43,570 --> 00:02:44,830 background, green. 42 00:02:45,900 --> 00:02:49,560 Let's go back into our activity_fun_facts layout file and 43 00:02:49,560 --> 00:02:50,850 make sure we're on the Design tab. 44 00:02:52,090 --> 00:02:54,750 Then let's select our relativeLayout and 45 00:02:54,750 --> 00:02:56,830 copy the green color from the background property. 46 00:02:59,906 --> 00:03:04,857 Then let's select our button, scroll down to the textColor property, 47 00:03:10,018 --> 00:03:12,350 Paste in our color and hit Enter. 48 00:03:13,860 --> 00:03:15,600 And there we go, green text. 49 00:03:16,700 --> 00:03:19,130 Now let's run the app and make sure everything works. 50 00:03:21,420 --> 00:03:24,340 Okay, just like we expected. 51 00:03:24,340 --> 00:03:26,850 Lots of different colors for the background and 52 00:03:26,850 --> 00:03:28,740 lots of different colors for the button text. 53 00:03:30,510 --> 00:03:33,240 All right, the app's really coming together. 54 00:03:33,240 --> 00:03:34,740 We're done with all the programing but 55 00:03:34,740 --> 00:03:38,290 there's still one little thing before we can move on to testing and debugging.