User Tools

Site Tools


android_learning:headfirst_android_development_notes:chapter_9

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
android_learning:headfirst_android_development_notes:chapter_9 [2016/03/03 02:07] – [v7 appcompat libraries] mithatandroid_learning:headfirst_android_development_notes:chapter_9 [2016/03/16 03:34] (current) – [p. 370: Creating the project] mithat
Line 1: Line 1:
-<WRAP center round important 90%>+====== Chapter 9 ====== 
 +<WRAP center round important 60%>
 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. 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.
 </WRAP> </WRAP>
- 
-====== Chapter 9 ====== 
 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. 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 cluster fudge 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.+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. 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.
Line 16: Line 15:
 </WRAP> </WRAP>
    
 +It will hurt if you don't.
  
-It will hurt if you don't. Be sure you specify an Empty app template in the new app wizard.+Be sure you specify an **Empty app template** in the new app wizard.
  
 ==== menu_main.xml ==== ==== menu_main.xml ====
Line 51: Line 51:
 ===== p. 372 ===== ===== p. 372 =====
 Open up ''AndroidManifest.xml'' and add<code xml>android:label="@string/app_name"</code> to the <activity> element. You might want to verify that the ''@string/app_name'' resource exists. Open up ''AndroidManifest.xml'' and add<code xml>android:label="@string/app_name"</code> to the <activity> 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 ===== ===== p. 374 =====
-Now lets take care of the problem caused by the "Theme.AppCompat.Light.DarkActionBar" reference. Open ''styles.xml''. Change <code xml><style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"></code> to  <code xml><style name="AppTheme" parent="android:Theme.Material.Light"></code>+Now let'take care of the problem caused by the "Theme.AppCompat.Light.DarkActionBar" reference. Open ''styles.xml'' and change <code xml><style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"></code> to  <code xml><style name="AppTheme" parent="android:Theme.Material.Light"></code>
 Also get rid of the items for colorPrimary, colorPrimaryDark, and colorAccent. Also get rid of the items for colorPrimary, colorPrimaryDark, and colorAccent.
  
-If you are seeing errors now, it might be because you forgot to specify a minimum API level of 21. You can fix that now by opening //File > Project Structure...// and selecting //app > Flavors// and for the defaulConfig's Min Sdk Version, manually type in 21.+If you are seeing errors now, it might be because you forgot to specify a minimum API level of 21 when you create the app. You can fix that now by opening //File > Project Structure...// and selecting //app > Flavors// and for the defaulConfig'"Min Sdk Version", manually type in 21.
  
 Try running the app. It's smoother sailing from here out. Try running the app. It's smoother sailing from here out.
Line 71: Line 73:
 </code> </code>
  
-Be sure to use ''android:showAsAction'' rather than ''app:showAsAction''. The former works with "native" action bars; the latter is the syntax if you're using the compatibility libraries. Isn't that nice?+Be sure to use ''android:showAsAction'' rather than ''app:showAsAction''. The former works with "native" action bars; the latter is the syntax if you're using the compatibility libraries. 
 + 
 +Isn't that nice?
  
 Add the "@string/action_create_order" resource with a value of "Create order". Add the "@string/action_create_order" resource with a value of "Create order".
  
 ==== The icons ==== ==== The icons ====
-The code above references "@drawable/ic_action_new_event", which means Android is expecting to see ''ic_action_new_event.png'' icon files in the ''drawables'' folders. Don't bother looking for the specified icon files in the file you're directed to download in the text. They're not there any moreWhee.+The code above references "@drawable/ic_action_new_event", which means Android is expecting to see ''ic_action_new_event.png'' icon files in the ''drawables'' folders. Don't bother looking for the specified icon files in the file you're directed to download in the text. They're not there anymoreFor reasons known only to the Google, they've been removed.
  
-Instead the authors are now recommending you grab images from the ''drawables-*'' folders at http://tinyurl.com/HeadFirstAndroidNewEventIcons and drop them into folders of the same name in your project. You'll probably have to create your corresponding ''drawables-*'' folders. Or you can grab {{:android_learning:headfirst_android_development_notes:ch9-drawable-folders-with-images.zip|this zip}} that has the folders with images already in them.+Whee. 
 + 
 +Instead the authors are now recommending you grab images from the ''drawables-*'' folders at http://tinyurl.com/HeadFirstAndroidNewEventIcons and drop them into folders of the same name in your project. You'll probably have to create the corresponding ''drawables-*'' folders. Or you can grab {{:android_learning:headfirst_android_development_notes:ch9-drawable-folders-with-images.zip|this zip}} that has the folders with images already in them.
  
  
 ===== p. 380 ===== ===== p. 380 =====
-The author's code on this page doesn't need to be modified. Yay.+The author's code on this page doesn't need to be modified. 
 + 
 +Yay.
 <code java> <code java>
 @Override @Override
Line 116: Line 124:
 ===== p. 382 ===== ===== p. 382 =====
  
-Be sure to create a new Empty activity. It should automagically generate as child class of Activity. Create a menu file for this activity as you did before.+Be sure to create a new Empty activity. It should automagically generate with parent class of Activity. Create a menu file for this activity as you did before.
  
 ===== p. 383 ===== ===== p. 383 =====
Line 202: Line 210:
  
 ===== p. 392 ===== ===== p. 392 =====
-Curiouslyin the manifest if you don'add either<code xml>android:parentActivityName=".MainActivity"</code> or the meta-data stuff to the OrderActivity's properties, the Up button still works fineMost probably an API change---but when did it happen? Whenever it wanted. +Since this app isn't supporting API 16 and lower, you don'need the ''meta-data'' stuff for the OrderActivity in ''AndroidManifest.xml''.
 ===== p. 393 ===== ===== p. 393 =====
 Code it like you see it. Code it like you see it.
android_learning/headfirst_android_development_notes/chapter_9.1456970853.txt.gz · Last modified: 2016/03/03 02:07 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki