About This E-Book EPUB is an open, industry-standard format for e-books. However, support for EPUB and its many features varies across reading devices and applications. Use your device or app settings to customize the presentation to your liking. Settings that you can customize often include font, font size, single or double column, landscape or portrait mode, and figures that you can click or tap to enlarge. For additional information about the settings and features on your reading device or app, visit the device manufacturer’s Web site. Many titles include programming code or configuration examples. To optimize the presentation of these elements, view the e-book in single-column, landscape mode and adjust the font size to the smallest setting. In addition to presenting code and configurations in the reflowable text format, we have included images of the code that mimic the presentation found in the print book; therefore, where the reflowable format may compromise the presentation of the code listing, you will see a “Click here to view code image” link. Click the link to view the print-fidelity code image. To return to the previous page viewed, click the Back button on your device or app. Android™ User Interface Design Implementing Material Design for Developers Second Edition Ian G. Clifton New York • Boston • Indianapolis • San Francisco Toronto • Montreal • London • Munich • Paris • Madrid Cape Town • Sydney • Tokyo • Singapore • Mexico City Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at [email protected] or (800) 382-3419. For government sales inquiries, please contact [email protected]. For questions about sales outside the U.S., please contact [email protected]. Visit us on the Web: informit.com/aw Library of Congress Control Number: 2015950113 Copyright © 2016 Pearson Education, Inc. All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, 200 Old Tappan Road, Old Tappan, New Jersey 07675, or you may fax your request to (201) 236-3290. Google is a registered trademark of Google, Inc. Android, Chromecast, Gmail, Google Maps, Google Play, and Nexus are trademarks of Google, Inc. Amazon and Kindle Fire are registered trademarks of Amazon.com, Inc. Java is a registered trademark of Oracle and/or its affiliates. Java is a registered trademark of Oracle and/or its affiliates. Illustrator and Photoshop are registered trademarks of Adobe Systems Incorporated. ISBN-13: 978-0-134-19140-9 ISBN-10: 0-134-19140-4 Text printed in the United States on recycled paper at RR Donnelley in Crawfordsville, Indiana. First printing: November 2015 Editor-in-Chief Mark Taub Executive Editor Laura Lewin Development Editor Songlin Qiu Managing Editor Kristy Hart Project Editor Namita Gahtori Copy Editor Cenveo® Publisher Services Indexer Cenveo Publisher Services Proofreader Cenveo Publisher Services Technical Reviewers Cameron Banga Joshua Jamison Adam Porter Editorial Assistant Olivia Basegio Cover Designer Chuti Prastersith Compositor Cenveo Publisher Services Dedicated to those who care about user experience Contents at a Glance Introduction Part I The Basics of Android User Interfaces 1 Android UI and Material Design 2 Understanding Views—The UI Building Blocks 3 Creating Full Layouts With View Groups and Fragments 4 Adding App Graphics and Resources Part II The Full Design and Development Process 5 Starting A New App 6 Prototyping and Developing the App Foundation 7 Designing the Visuals 8 Applying the Design 9 Polishing with Animations Part III Advanced Topics for Android User Interfaces 10 Using Advanced Techniques 11 Working with the Canvas and Advanced Drawing 12 Developing Custom Views 13 Handling Input and Scrolling Appendix A Google Play Assets Appendix B Common Task Reference Index Contents Introduction Audience for This Book Organization of This Book How to Use This Book This Book’s Website Conventions Used in This Book Part I The Basics of Android User Interfaces 1 Android UI and Material Design A Brief History of Android Design Material Design The Android Design Website Core Principles Standard Components Supporting Multiple Devices Avoiding Painful Mistakes Summary 2 Understanding Views—The UI Building Blocks What Is a View? Displaying Text Displaying Images Views for Gathering User Input Other Notable Views Listening to Events Other Listeners Summary 3 Creating Full Layouts With View Groups and Fragments