====== Chapter 9 ====== The changes to Android Studio 1.5.1 have put this chapter well out of sync with both the "Blank Activity" and "Empty Activity" templates. So while this isn't a very long chapter, there will be a //lot// of corrections/addenda. It might be a little ambiguous in the Chapter intro, so here's a summary of what you're going to do in the chapter. You will build an app that has an //action bar//. An action bar is space at the top of an app that holds the activity name or other info on the left (in LTR languages) as well as a menu on the right (in LTR languages). The menu will have a number of items; some of those items will be specified to be pulled out of the drop down list and placed on the action bar as //action buttons// alongside the menu. The action bar is a bit of a clustercuss at the moment. It wasn't to Android added until relatively recently, and if you want to build apps using action bars that target older versions of Android, you'll have to use compatibility libraries. The syntax when compatibility libraries is just different enough from current Android "native" action bars to make things maximally painful to move from one to the other. Another issue is that the compatibility libraries seem to be buggier than the current Android "native" action bars. So, I think it's best not to mess around with the compatibility libraries at first. Let the fun begin. ===== p. 370: Creating the project ===== When creating the project, set the minimum API level to **21** (not 17). It will hurt if you don't. Be sure you specify an **Empty app template** in the new app wizard. ==== menu_main.xml ==== The Empty activity template does not generate a ''menu_main.xml'' file, so you'll have to add one manually. In Android Studio, right click on the ''res'' folder in the Android view, select //New > Menu resource file//, and give the file the name ''menu_main.xml''. Then replace the contents of that file with the following: and create a string resource Settings The ''main_menu.xml'' code you entered above will probably show you that there are errors. If this is the case, it means that Android Studio set up your app to use the compatibility libraries. The book tries to show you how to build the app either way, but we're only going to build this //not// using the compatibility libraries. ==== v7 appcompat libraries ==== Way over on p. 385 there is an aside about action items not appearing when using some versions of the v7 appcompat library because of an Android bug. I've been bit by this and it stands as the main reason I suggest not trying to use them for your maiden action bar voyage. So, start by removing the project's dependency on the v7 appcompat library by using //File > Project Structure...// and selecting //app > Dependencies//, then right clicking on the appropriate entry to remove it. This will make ''MainActivity.java'' very angry. Make MainActivity extend Activity rather than ActionBarActivity (and fixing imports), and this will make ''MainActivity.java'' a little happier. But you'll probably notice that ''R'' is broken. ''R'' is broken at this point because ''styles.xml'' makes reference to a "Theme.AppCompat.Light.DarkActionBar" value, which no longer exists because we're not using the compatibility libraries any more. We'll fix that shortly. Isn't this fun? ===== p. 372 ===== Open up ''AndroidManifest.xml'' and addandroid:label="@string/app_name" to the element. You might want to verify that the ''@string/app_name'' resource exists. If a label isn't specified for an activity, Android will use the app's label instead. In this case we are setting the activity's label to be the same as the app's label, but this doesn't have to be the case. ===== p. 374 ===== Now let's take care of the problem caused by the "Theme.AppCompat.Light.DarkActionBar" reference. Open ''styles.xml'' and change