Options Menu not working with Target SDK 21


#1

Note, I had to switch to the Android Studio as of Chapter 33 and I have targetSDKVersion 21, minSDKVersion 9 and compileSDKVersion 21. Chapter 34 seems to work however the options menu is not displayed. Of course, I cannot test out the create new run without the options menu.

Android Studio gives an error in res/menu/run_list_options.

Error message: Should use app showAsAction with the appcompat library with xmlns:app=“http://schemas.android.com/tools

I did try changing the res_list_options as suggested by Android Studio, as follows

[code]<?xml version="1.0" encoding="utf-8"?>

[/code]

However, the Options menu is still not inflated. Can anyone offer any suggestions or hints to resolve this issue?


#2

@mrpeanut Don’t know if you resolved it but just in case:

if the options menu isn’t showing, you might have forgotten to add in your onCreate() in RunListFragment

As for the error which android studio shows in you xml, you can ignore it and still use android: as the project will still compile. For me using app: it would put the menu item inside the 3 dots of the overflow menu. Using android: would show the icon on the actionbar as desired.

I think the error that android studio displays is a small bug due to the change that was made by google in lollipop when implementing the new Toolbar which replaces the ActionBar.


#3

Hi thanks for the hints …

I actually found the root cause to this problem over the holidays. Since this is my little side hobby I’ve not had a chance to come and update the forum. You may recall from the initial post that I switched to the Android Studio IDE. The fundamental problem was that the project was setup with a default App theme by Android Studio that did not support the Action Bar menus. I didn’t see the option to change layout in the project setup menus (I have tried setting up a project multiple times). However, the fix is easy, simply change to a layout that supports Action Bar menus. There are at least a couple of ways to to do this.

Option 1: within the Android Studio Layout “Design” window click on App Themes and select a theme, such as Holo Light
Option 2: in the AndroidManifest.xml modify the line for App theme to something like “android:theme=”@android:style/Theme.Holo" >"

Happy coding …