Adding an icon to the view

Next, we'll add an icon image to the view.

For now, let's just use a generic icon, such as android_robot.png. A copy of this can be found on the Internet, and there's a copy included with the files for this chapter. Paste the android_robot.png file into your project's app/res/drawable/ folder. Don't worry, we'll be using the actual app icons later.

We want to display both the text and an icon together, so we can add the code in order to add the image views to the addContent method.

In the onCreate method of MainActivity, modify the addContent call to pass the icon as a second parameter:

        Drawable icon = getResources()
            .getDrawable(R.drawable.android_robot, null);
        overlayView.addContent("Hello Virtual World!", icon);

In

Get Cardboard VR Projects for Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.