As a developer, the better you understand your tools, the more productive you get.
In the series, I’m going to cover some essential and helpful tips and tricks based on our daily usage scenarios, to help you to get the most out of Android Studio.
Key concept: Mouseless-Driven Developement
An over-dependence on using your mouse while coding can have results of being lower productivity. That is why that we emphasize the Mouseless-Drive Development. Try to use the keyboard shortcut as much as possible can help you be more productive. The keyboard shortcuts in this article are based on default keymaps on MacOS. Linux and Windows equivalents can be found here. And I use the following symbols to represent key.
- ⌘ = Command Key
- ⌥ = Option (Alt) Key
- ⇧ = Shift Key
- ⌃ = Control Key
During the time we develop a great Android app, we may spend more time nagivating in our code than you can image, so I choose Navigation as the first topic in this series. Let’s get started to learn how to navigate code efficiently.
Search Everywhere: Double ⇧Shift
The most wild and powerful search from your entire project. If you don’t have any idea how to find the thing you want, just type double SHIFT to search everywhere.
Navigate -> File (or Class, Symbol)
The Shortcut keys for Navigate -> File / Class / Symbo are [⌘ + ⇧ + O] / [⌘ + O] / [⌘ + ⌥ + O] respeatively. You can browse any file in your project, such Java file, xml layout, drawable, string resource file…etc. Or if you know that is a class or symbol in advance, please use
Navigate -> Class / Symbol.
File structure: ⌘ + F12
Navigate -> File Structures.This will list all the constants, instance / static variables, methods, inner classes…etc in the file. I usually use this to jump to a specific methods in a class file.
Go to Line: ⌘ + L
When opening a file, you can go to a exact line by
Navigate -> Line/Column.
Recent Files: ⌘ + E
I often copy / check code / do some stuff from other file, after performing whatever I do, how can I go back to the original file right away? Use
View -> Recent FIles.
Call Hierarchy: ⌥ + ⌃ + H
How do I find all the caller of a specific method? Use
Navigate -> Call Hierarchy. You can find the whole calling path from the start of the method.
Type Hierarchy: ⌃ + H
How do I find the class inheritance hierarchy? How can I find which classes extends another class and vice versa? Or how can I find which classes implement this interface? Use
Nagivate -> Type Hierarchy.
Find Usages: ⌥ + F7
How do I find where/who uses a field / method / class / file? Use
Edit -> Find -> Find Usages. The result will be shown grouped by value read and write.
Find in Paths: ⌘ + ⇧ + F
The alternative way to find usages is Find in Paths with more powerful searching. Use
Edit -> Find -> Fine in Paths. You can specify where to search, how to match your keyword.
Android Studio supports different search modes:
- Match case: The search is cast-sensitive.
- Words: The search results must match the whole word only (and case-sensitive).
- Regex: The search term will be perceived as a regular expression.
- File mask: You can specify the file matching pattern, such as
*.ktfor searching kotlin source code files.
In the next article, we will take a look at some useful tips when we write the code.