The Options Menu2:39 with Ben Deitch
In this video we'll learn about what an Options Menu is, and we'll take a look at the app we'll be creating!
When looking for a library to help handle images, Glide is a popular choice; Google even uses Glide in some of their own applications! Also, Glide relies on V4 of the support library to run. So if you decide to use glide in your own projects, remember that you'll need to add two dependencies - one for 'glide', and one for 'support-v4'.
[MUSIC] 0:00 Hey there. 0:04 I'm Ben, and in this workshop we're going to learn how to use the options menu. 0:05 The options menu is the set of options you usually see at the top of an application, 0:10 and it's where you should place any actions related to the current activity. 0:14 Let's take a look at the app we'll be making to get acquainted with 0:18 the options menu. 0:20 In this workshop we'll be making an app to let us change the colors 0:22 of a few preloaded images. 0:25 Up here is the options menu, where we have two items being displayed, and 0:27 four more in the overflow menu. 0:32 The first item lets us cycle through the three images. 0:35 And the second one toggles the image between color, and black and white. 0:39 In the overflow menu we have a check box for each color channel. 0:45 And if we uncheck one, that color is removed from the image. 0:48 Finally, the Reset button just resets the image to normal. 0:53 And one more thing, if we have a black and 0:57 white image, it doesn't really make sense to remove color from it. 0:59 So we're not going to show the color options unless it's 1:04 actually a color image. 1:07 That's enough about the project for now, let's start making it. 1:08 If you'd like to follow along, pause me and 1:12 download the starter project from the teacher's notes below. 1:14 All right, now that we've got our project, let's open up MainActivity and 1:17 see what we're working with. 1:20 At the top we've got a few fields. 1:27 There's one for our imageView, followed by an array to store our resource IDs, and 1:30 an imageIndex to store which resource ID we're using. 1:35 Then there's a boolean variable to determine if the image is in color. 1:39 And finally three more booleans to determine whether each color 1:43 should be on or off. 1:47 In the onCreate method, we just set our layout, 1:50 populate the imageView field, and then call the loadImage method. 1:53 If you try to load a large image into an imageView, 1:57 Android will throw an out of memory error. 2:01 However, by using the Glide library, we don't have to worry about that, and 2:03 we can just load the image right into the imageView. 2:07 At the bottom of the class, we have two more functions that aren't being used yet. 2:11 The first is updateSaturation, which will toggle the image between color, and 2:15 black and white, depending on the value of our color field. 2:19 The second method is updateColors. 2:23 This method will set the colors of our image based on the values of the red, 2:27 green, and blue fields. 2:32 All right, that should be enough to get us started. 2:33 In the next video we'll start implementing our options menu. 2:36
You need to sign up for Treehouse in order to download course files.Sign up