Book Description

What will you learn from this book?

If you have an idea for a killer Android app, this fully revised and updated edition will get you up and running in a jiffy. You’ll go beyond syntax and how-to manuals and learn how to think like a great Android developer. This hands-on book teaches you everything from designing layouts to the latest features of Android Jetpack. It’s like having an experienced Android developer sitting right next to you! If you have some Kotlin know-how, you’re ready to get started.

Why does this book look so different?

Based on the latest research in cognitive science and learning theory, Head First Android Development uses a visually rich format to engage your mind rather than a text-heavy approach that puts you to sleep. Why waste your time struggling with new concepts? This multisensory learning experience is designed for the way your brain really works.

Table of Contents

  1. 1. Getting Started: Diving In
    1. Welcome to Androidville
      1. Layouts define what each screen looks like
      2. Activities define what the app does
      3. Extra resources may be needed too
    2. Activities and layouts form the backbone of your app
    3. Here’s what we’re going to do
    4. Android Studio: your development environment
      1. You need to install Android Studio
    5. Install Android Studio
    6. Build a basic app
    7. How to build the app
      1. 1. Create a new project
      2. 2. Choose your project
      3. 3. Configure your project
    8. You’ve created your first Android project
    9. Dissecting your new project
      1. The folder structure includes different types of files
    10. Introducing the key files in your project
    11. Edit code with the Android Studio editors
      1. The code editor
      2. The design editor
    12. The story so far...
    13. How to run the app on a physical device
      1. 1. Enable USB debugging on your device
      2. 2. Set up your computer to detect the device
      3. 3. Use a USB cable to plug your device into your computer
      4. 4. Run your app
    14. How to run the app on a virtual device
    15. Create an Android Virtual Device (AVD)
      1. Open the Android Virtual Device Manager
      2. Select the hardware
      3. Select a system image
      4. Verify the AVD configuration
      5. The virtual device gets created
      6. Run the app on the AVD
    16. Compile, package, deploy, run
    17. Test drive
    18. What just happened?
    19. Refine the app
      1. The app has one activity and one layout
      2. The activity controls what the app does
      3. The layout controls the app’s appearance
    20. What’s in the layout?
      1. The design editor
      2. The code editor
    21. activity_main.xml has two elements
    22. Update the text displayed in the layout
    23. What the code does
    24. Test drive
    25. Your Android Toolbox
  2. 2. Building Interactive Apps: Apps That Do Something
    1. Let’s build a Beer Adviser app
    2. Here’s what we’re going to do
    3. Create the project
    4. We’ve created a default activity and layout
    5. A closer look at the design editor
    6. Add a button using the design editor
      1. Changes in the design editor are reflected in the XML
    7. activity_main.xml has a new button
      1. Buttons and text views are subclasses of the same Android View class
      2. android:id
      3. android:layout_width, android:layout_height
      4. android:text
    8. A closer look at the layout code
    9. The <LinearLayout> element
      1. The Button element
      2. The TextView element
    10. Let’s update the layout XML
    11. The XML changes are reflected in the design editor
    12. Test drive
    13. There are warnings in the layout...
      1. ...because there’s hardcoded text
    14. Put text in a String resource file
      1. Android Studio helps you extract String resources
    15. Extract the String resource
      1. A String resource has been added to strings.xml
    16. activity_main.xml uses the String resource
      1. You also can extract String resources manually
    17. Add and use a new String resource
    18. Test drive
    19. Add values to the spinner
      1. Adding an array resource is similar to adding a String
    20. Add the string-array to strings.xml
      1. Get the spinner to display the array’s values
    21. The full code for activity_main.xml
    22. Test drive
    23. We need to make the app interactive
    24. What our MainActivity code looks like
    25. A button can listen for on-click events...
      1. ...using an OnClickListener
    26. Get a reference to the button...
      1. ...and call its setOnClickListener method
    27. Pass a lambda to the setOnClickListener method
    28. How to edit a text view’s text
      1. How to get the spinner’s selected value
    29. The updated code for MainActivity.kt
    30. What happens when you run the code
    31. Test drive
    32. Add the findBeers function
    33. The full code for MainActivity.kt
    34. What happens when you run the code
    35. Test drive
    36. Your Android Toolbox
  3. 3. Views and View Groups: Enjoy the View
    1. It all starts with a layout
    2. All UI components are a type of view...
    3. ...and all layouts are a type of view group
    4. What we’re going to do
      1. Create a new project
    5. Let’s build a linear layout
    6. How to define a linear layout
    7. Orientation can be vertical or horizontal
    8. Padding adds space to the layout’s edges
    9. Add a dimension resource file for consistent padding across layouts
    10. Our layout code so far
    11. Add UI components to the linear layout
    12. A linear layout displays views in the order they appear in the layout XML
    13. Make a view streeeeetch by adding weight
    14. How to add weight to one view
    15. How to add weight to multiple views
    16. The gravity attribute controls the position of a view’s contents
    17. Values you can use with the android:gravity attribute
    18. Layout Magnets
      1. Layout Magnets Solution
    19. The story so far
    20. layout-gravity controls the position of a view within a layout
    21. More values you can use with the android:layout-gravity attribute
    22. Use margins to add space between views
    23. The full linear layout code
    24. Test drive
      1. BE the Layout
      2. BE the Layout Solution
    25. A frame layout stacks its views
      1. Create a new project
      2. How to define a frame layout
    26. Add an image to your project
    27. A frame layout stacks views in the order they appear in the layout XML
      1. Test drive
    28. A scroll view inserts a vertical scrollbar
    29. How to add a scroll view
    30. Test drive
    31. Layouts are a type of View called a ViewGroup
    32. Android inflates views into objects
    33. Let’s visit the View Zoo
    34. An edit text lets you enter text
      1. How to use an edit text in your activity code
    35. Toggle buttons, switches and checkboxes are buttons that have two states
    36. How to use a compound button in your activity code
    37. Radio buttons let you select a single option
    38. An image view displays an image
      1. Adding an image to your project
    39. Image view: the layout XML
      1. Using image views in your activity code
    40. Toasts
      1. Using it in your activity code
    41. Your Android Toolbox
  4. 4. Constraint Layouts Put Things in Their Place
    1. Nested layouts revisited
    2. Nested layouts can be inefficient
    3. Introducing the constraint layout
      1. You design constraint layouts VISUALLY
    4. Create a new project
      1. Add the String resources to strings.xml
      2. Make activity_main.xml use a constraint layout
    5. Use the blueprint tool
    6. Position views using constraints
      1. We’ll add a horizontal constraint to the button
    7. Add a vertical constraint
      1. Changing the view’s margins
    8. Changes to the blueprint are reflected in the XML
    9. How to center views
    10. Adjust a view’s position by updating its bias
    11. How to change a view’s size
      1. 1. Make the view a fixed size
      2. 2. Make it just big enough
      3. 3. Match the view’s constraints
      4. 4. Specify the width:height ratio
    12. BE the Constraint
    13. BE the Constraint Solution
    14. How to align views
    15. Let’s build a real layout
    16. First, add the top line of views
    17. Get the design editor to infer the constraints
    18. The Infer Constraints feature guesses which constraints to add
    19. Add the next line to the blueprint...
      1. ...and then add the button
    20. Finally, add a view for the message
    21. Test drive
    22. Your Android Toolbox