Table Of ContentAndroid 5 Programming
by Example
Turn your ideas into elegant and powerful mobile
applications using the latest Android Studio for the
Android Lollipop platform
Kyle Mew
BIRMINGHAM - MUMBAI
Android 5 Programming by Example
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
First published: July 2015
Production reference: 1210715
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78528-844-9
www.packtpub.com
Credits
Author Project Coordinator
Kyle Mew Vijay Kushlani
Reviewers Proofreader
Mustafa Gezen Safis Editing
Olivier Goutay
Ten Wong Indexer
Mariammal Chettiyar
Commissioning Editor
Neil Alexander Graphics
Abhinash Sahu
Acquisition Editor
Vivek Anantharaman Production Coordinator
Nilesh R. Mohite
Content Development Editor
Nikhil Potdukhe Cover Work
Nilesh R. Mohite
Technical Editors
Ruchi Desai
Chinmay S. Puranik
Copy Editors
Ulka Manjrekar
Swati Priya
About the Author
Kyle Mew has been programming since the early 80s and has written for several
technology websites. He has also written three radio plays and another book on
Android development, Android 3.0 Application Development Cookbook, published by
Packt Publishing.
I would like to thank Rhonda for the photographs.
About the Reviewers
Mustafa Gezen is a Norwegian developer who develops applications for both
Android and iOS devices. His early experiences with programming have helped
him develop amazing stuff. He likes to take things apart and make them function
differently. He has experience in Python, Objective-C, Java, PHP and some other
languages. His main field of interest is runtime code modification.
I would like to thank my amazing family for supporting me in what
I do, always believing in me, and putting their trust in me.
Olivier Goutay is an expert in Android application development. With more than
3 years of professional experience, he currently takes part in healthcare and open
source Android developments in San Francisco. He currently works for Omada
Health, the lead start-up in chronic disease prevention in the U.S.
Before this, he was involved with major French and European Bank mobile services
and developed tomorrow's technologies, which are now used by many people on
their mobile devices.
His specialties are Android development, software security, software architecture,
and iOS.
Ten Wong is an embedded software engineer at Seeed Studio, an open source
hardware company. He has 3 years of experience in Android driver and framework.
He also has experience in TV Android app development and Arduino open source
hardware shield.
I would like to thank my wife for supporting me in reviewing
this book.
www.PacktPub.com
Support files, eBooks, discount offers, and more
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF
and ePub files available? You can upgrade to the eBook version at www.PacktPub.
com and as a print book customer, you are entitled to a discount on the eBook copy.
Get in touch with us at service@packtpub.com for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign
up for a range of free newsletters and receive exclusive discounts and offers on Packt
books and eBooks.
TM
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser
Free access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view 9 entirely free books. Simply use your login credentials for
immediate access.
Table of Contents
Preface v
Chapter 1: Setting Up the Development Environment 1
What is Android 5? 2
Lollipop from a user's perspective 2
Lollipop from a developer's perspective 3
Material Design 3
Other devices 3
Installing and configuring the development environment 4
Installing the SDK 5
Managing the SDK tools 6
Creating a "Hello World" app 9
Testing the app on a physical device 11
Setting up a virtual device 11
Monitoring devices 13
Summary 14
Chapter 2: Building a UI 15
Applying a Material Design theme 16
Adding animated widgets 20
Designing an XML layout 20
Controlling the widget behavior with Java 25
Creating alternative layouts 29
Summary 31
Chapter 3: Activities and Fragments 33
Adding a CardView widget 34
Adding images and text to the layout 37
Creating a second Activity 40
Applying Fragments 43
Adding static Fragments 49
[ i ]
Description:Project Coordinator. Vijay Kushlani. Proofreader. Safis Editing. Indexer. Mariammal Chettiyar. Graphics. Abhinash Sahu. Production Coordinator. Nilesh R. Mohite. Cover Work. Nilesh R. He also has experience in TV Android app development and Arduino open source hardware shield. I would like to