While it is tempting to plunge into running the example application created in the previous chapter, it involves using aspects of the Android Studio user interface, which are best described in advance.
Android Studio is a powerful and feature-rich development environment that is, to a large extent, intuitive to use. That being said, taking the time now to gain familiarity with the layout and organization of the Android Studio user interface will shorten the learning curve in later chapters of the book. With this in mind, this chapter will provide an overview of the various areas and components of the Android Studio environment.
The Welcome Screen
The welcome screen (Figure 6-1) is displayed any time that Android Studio is running with no projects currently open (open projects can be closed at any time by selecting the File -> Close Project menu option). If Android Studio was previously exited while a project was still open, the tool will bypass the welcome screen the next time it is launched, automatically opening the previously active project.
In addition to a list of recent projects, the welcome screen provides options for performing tasks such as opening and creating projects, along with access to projects currently under version control. In addition, the Customize screen provides options to change the theme and font settings used by both the IDE and the editor. Android Studio plugins may be viewed, installed, and managed using the Plugins option.
Additional options are available by selecting the More Actions link or using the menu shown in Figure 6-2 when the list of recent projects replaces the More Actions link:
The Menu Bar
The Android Studio main window will appear when a new project is created, or an existing one is opened. When multiple projects are open simultaneously, each will be assigned its own main window. The precise configuration of the window will vary depending on the operating system Android Studio is running on and which tools and panels were displayed the last time the project was open. The appearance, for example, of the main menu bar will differ depending on the host operating system. On macOS, Android Studio follows the standard convention of placing the menu bar along the top edge of the desktop, as illustrated in Figure 6-3:
When Android Studio is running on Windows or Linux, however, the main menu is accessed via the button highlighted in Figure 6-4:
The Main Window
Once a project is open, the Android Studio main window will typically resemble that of Figure 6-5:
The various elements of the main window can be summarized as follows:
- A – Toolbar – A selection of shortcuts to frequently performed actions. The toolbar buttons provide quick access to a select group of menu bar actions. The toolbar can be customized by right-clicking on the bar and selecting the Customize Toolbar… menu option. The toolbar menu shown in Figure 6-6 provides a convenient way to perform tasks such as creating and opening projects and switching between windows when multiple projects are open:
- B – Navigation Bar – The navigation bar provides a convenient way to move around the files and folders that make up the project. Clicking on an element in the navigation bar will drop down a menu listing the sub-folders and files at that location, ready for selection. Similarly, clicking on a class name displays a menu listing methods contained within that class:
Select a method from the list to be taken to the corresponding location within the code editor. You can hide, display, and change the position of this bar using the View -> Appearance -> Navigation Bar menu option.
- C – Editor Window – The editor window displays the content of the file on which the developer is currently working. When multiple files are open, each file is represented by a tab located along the top edge of the editor, as shown in Figure 6-8:
- D – Status Bar – The status bar displays informational messages about the project and the activities of Android Studio. Hovering over items in the status bar will display a description of that field. Many fields are interactive, allowing users to click to perform tasks or obtain more detailed status information.
The widgets displayed in the status bar can be changed using the View -> Appearance -> Status Bar Widgets menu.
- E – Project Tool Window – The project tool window provides a hierarchical overview of the project file structure allowing navigation to specific files and folders to be performed. The toolbar can be used to display the project in several different ways. The default setting is the Android view which is the mode primarily used in the remainder of this book. The project tool window is just one of many available tools within the Android Studio environment.
The Tool Windows
In addition to the project view tool window, Android Studio also includes many other windows, which, when enabled, are displayed tool window bars that appear along the left and right edges of the main window and contain buttons for showing and hiding each of the tool windows. Figure 6-10 shows typical tool window bar configurations, though the buttons and their positioning may differ for your Android Studio installation.
Clicking on a button will display the corresponding tool window, while a second click will hide the window. The location of a button in a tool window bar indicates the side of the window against which the window will appear when displayed. These positions can be changed by clicking and dragging the buttons to different locations in other window toolbars.
Android Studio offers a wide range of tool windows, the most commonly used of which are as follows:
- Project (A) – The project view provides an overview of the file structure that makes up the project allowing for quick navigation between files. Generally, double-clicking on a file in the project view will cause that file to be loaded into the appropriate editing tool.
- Resource Manager (B) – A tool for adding and managing resources and assets within the project, such as images, colors, and layout files.
- More Tool Windows (C) – Displays a menu containing additional tool windows not currently displayed in a tool window bar. When a tool window is selected from this menu, it will appear as a button in a tool window bar.
- Run (D) – The run tool window becomes available when an application is currently running and provides a view of the results of the run together with options to stop or restart a running process. If an application fails to install and run on a device or emulator, this window typically provides diagnostic information about the problem.
- Logcat (E) – The Logcat tool window provides access to the monitoring log output from a running application and options for taking screenshots and videos of the application and stopping and restarting a process.
- Problems (F) – A central location to view all of the current errors or warnings within the project. Double-clicking on an item in the problem list will take you to the problem file and location.
- App Quality Insights (G) – Provides access to the cloud-based Firebase app quality and crash analytics platform.
- Terminal (H) – Provides access to a terminal window on the system on which Android Studio is running. On Windows systems, this is the Command Prompt interface, while on Linux and macOS systems, this takes the form of a Terminal prompt.
- Version Control (I) – This tool window is used when the project files are under source code version control, allowing access to Git repositories and code change history.
- Notifications (J) – This tool window is used when the project files are under source code version control, allowing access to Git repositories and code change history.
- Gradle (K) – The Gradle tool window provides a view of the Gradle tasks that make up the project build configuration. The window lists the tasks involved in compiling the various elements of the project into an executable application. Right-click on a top-level Gradle task and select the Open Gradle Config menu option to load the Gradle build file for the current project into the editor. Gradle will be covered in greater detail later in this book.
- Device Manager (L) – Provides access to the Device Manager tool window where physical Android device connections and emulators may be added, removed, and managed.
- Running Devices (M) – Contains the AVD emulator if the option has been enabled to run the emulator in a tool window as outlined in the chapter entitled Creating an Android Virtual Device (AVD) in Android Studio.
- App Inspection – Provides access to the Database and Background Task inspectors. The Database Inspector allows you to inspect, query, and modify your app’s databases while running. The Background Task Inspector allows background worker tasks created using WorkManager to be monitored and managed.
- Bookmarks – The Bookmarks tool window provides quick access to bookmarked files and code lines. For example, right-clicking on a file in the project view allows access to an Add to Bookmarks menu option. Similarly, you can bookmark a line of code in a source file by moving the cursor to that line and pressing the F11 key (F3 on macOS). All bookmarked items can be accessed through this tool window.
- Build – The build tool window displays information about the build process while a project is being compiled and packaged and details of any errors encountered.
- Build Variants – The build variants tool window provides a quick way to configure different build targets for the current application project (for example, different builds for debugging and release versions of the application or multiple builds to target different device categories).
- Device File Explorer – Available via the View -> Tool Windows -> Device File Explorer menu, this tool window provides direct access to the filesystem of the currently connected Android device or emulator, allowing the filesystem to be browsed and files copied to the local filesystem.
- Layout Inspector – Provides a visual 3D rendering of the hierarchy of components that make up a user interface layout.
- Structure – The structure tool provides a high-level view of the structure of the source file currently displayed in the editor. This information includes a list of items such as classes, methods, and variables in the file. Selecting an item from the structure list will take you to that location in the source file in the editor window.
- TODO – As the name suggests, this tool provides a place to review items that have yet to be completed on the project. Android Studio compiles this list by scanning the source files that make up the project to look for comments that match specified TODO patterns. These patterns can be reviewed and changed by opening the Settings dialog and navigating to the TODO entry listed under Editor.
The Tool Window Menus
Each tool window has its own toolbar along the top edge. The menu buttons within these toolbars vary from one tool to the next, though all tool windows contain an Options menu (marked A in Figure 6-11):
The Options menu allows various aspects of the window to be changed. Figure 6-12, for example, shows the Options menu for the Project tool window. Settings are available, for example, to undock a window and to allow it to float outside of the boundaries of the Android Studio main window, and to move and resize the tool panel:
All tool windows also include a far-right button on the toolbar (marked B in Figure 6-11 above), providing an additional way to hide the tool window from view. A search of the items within a tool window can be performed simply by giving that window focus by clicking on it and then typing the search term (for example, the name of a file in the Project tool window). A search box will appear in the window’s toolbar, and items matching the search are highlighted.
Android Studio Keyboard Shortcuts
Android Studio includes many keyboard shortcuts to save time when performing common tasks. A complete keyboard shortcut keymap listing can be viewed and printed from within the Android Studio project window by selecting the Help -> Keyboard Shortcuts PDF menu option. You may also list and modify the keyboard shortcuts by opening the Settings dialog and clicking on the Keymap entry, as shown in Figure 6-13 below:
Switcher and Recent Files Navigation
Another useful mechanism for navigating within the Android Studio main window involves using the Switcher. Accessed via the Ctrl-Tab keyboard shortcut, the switcher appears as a panel listing both the tool windows and currently open files (Figure 6-14).
Once displayed, the switcher will remain visible as long as the Ctrl key remains depressed. Repeatedly tapping the Tab key while holding down the Ctrl key will cycle through the various selection options while releasing the Ctrl key causes the currently highlighted item to be selected and displayed within the main window.
In addition to the Switcher, the Recent Files panel provides navigation to recently opened files (Figure 6-15). This can be accessed using the Ctrl-E keyboard shortcut (Cmd-E on macOS). Once displayed, either the mouse pointer can be used to select an option, or the keyboard arrow keys can be used to scroll through the file name and tool window options. Pressing the Enter key will select the currently highlighted item:
Changing the Android Studio Theme
The overall theme of the Android Studio environment may be changed using the Settings dialog. Once the settings dialog is displayed, select the Appearance & Behavior option in the left-hand panel, followed by Appearance. Then, change the setting of the Theme menu before clicking on the OK button. The themes available will depend on the platform but usually include options such as Light, IntelliJ, Windows, High Contrast, and Darcula. Figure 6-16 shows an example of the main window with the Dark theme selected:
To synchronize the Android Studio theme with the operating system light and dark mode setting, enable the Sync with OS option and use the drop-down menu to control which theme to use for each mode:
The primary elements of the Android Studio environment consist of the welcome screen and main window. Each open project is assigned its own main window, which, in turn, consists of a menu bar, toolbar, editing and design area, status bar, and a collection of tool windows. Tool windows appear on the sides of the main window.
There are very few actions within Android Studio that cannot be triggered via a keyboard shortcut. A keymap of default keyboard shortcuts can be accessed at any time from within the Android Studio main window.