This workshop will be retired on May 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
In this video we'll finish up our Options Menu and finally see the colors change!
Related Links
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
We, just finished hooking up our next
image button and our color button.
0:00
Now let's finish up the app, by hooking
up all the buttons on the overflow menu.
0:04
Let's start by adding a case for
when the red button is clicked.
0:08
Case R.id.red, and
0:11
add a break statement.
0:15
Then inside the case, let's toggle
the value of our red variable,
0:21
red = not red.
0:24
And then, call the updateColors method.
0:29
Lastly, since our checkboxes
don't do anything themselves,
0:33
we need to manually update them.
0:37
So let's call item,
which remember refers to our red menu
0:39
item.setChecked and pass in red to
make it match the underlying variable.
0:44
Awesome!
0:53
Now that we've got red taken care of,
let's copy and paste this block two times.
0:53
And then, let's make this one for green.
1:03
And, this one for blue.
1:11
Finally, all that's left
is the reset button.
1:19
Let's add one more case, for R.id.reset.
1:23
And, let's add our break statement.
1:30
And then,
to reset the image to its initial state,
1:33
we just need to call
Imageview.clearColorFilter.
1:37
We should also reset our red,
green, blue, and
1:43
color variables to all be true,
which we can do on one line, like this.
1:47
Red = green = blue = color = true.
1:52
Lastly, since we've made
changes to these variables,
1:59
we should also update the options menu.
2:03
So, let's add a call to invalidate
options menu, and that should do it.
2:06
We're ready to test the app.
2:11
Let's run it.
2:13
And then if we click on
one of our check boxes,
2:18
it removes that color from the image and
the box is unchecked.
2:22
Awesome.
2:27
And if we click on the reset button
after clicking a few check boxes,
2:28
the image goes back to normal and
the boxes get rechecked.
2:33
Perfect.
2:37
Great job putting together
this options menu.
2:38
If you'd like to learn
more about options menus,
2:41
check out the links in
the Teacher's notes below.
2:43
And as always, if you have any questions
or would like to try your hand
2:45
at answering other people's questions,
make your way over to the community.
2:49
Until next time.
2:52
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up