Android Studio: A Few Tips and Tricks
I want to share a few tips and tricks on Android Studio. This is not a comprehensive guide on how to use the IDE, and rather some of the tools I personally use to make myself more productive, and a few resources where you can learn more.
Use Keyboard Shortcuts
Keyboard shortcuts will help you to be more productive and here are a few examples of the ones that I often use -
- Cmd+, — open Preferences (Windows Ctrl+Alt+S for Settings)
- Cmd+Shift+O — open a file (Windows Ctrl+Shift+N)
- Alt+Cmd+L — reformat code (Windows Ctrl+Alt+L)
- Ctrl+Option+H — show call hierarchy (Windows Ctrl+Alt+H)
- Cmd + 9 — show local changes if your project has VCS enabled (i.e. linked to GitHub or BitBucket). Then you can View Diff and Commit the changes. (Windows Alt+9)
- Cmd+Alt+T, 2 — add region to your code which you can expand and collapse. More on code folding here. (Windows Ctrl+Alt+T, 2)
Here is the full list of keyboard shortcuts (both Windows/Linux and Mac) for Android Studio. If you can’t remember all the commands or don’t have time to look them up online, just remember this one: Cmd+Shift+A (Windows Ctrl+Shift+A) which allows you to search any command in Android Studio immediately. If that still doesn’t meet your needs, then you can define your own shortcuts by configuring custom keymaps. I learned about these tricks from one of the Fragmented podcasts by Donn Felker and Kaushik Gopal.
protip Use Cmd+Shift+A (or Ctrl+Shift+A on Windows) to find an action or command in Android Studio.
Presenting to an Audience
If you ever need to demo live coding or walk through code via a projector, it’s important to make it easier for your audience to see. Image you are in the middle of a presentation, and your audience says “we can’t see what you are trying to show us.” Ok, that has happened to a lot of us.
protip Improve readability of Android Studio during presentation, by changing the theme, increasing the font size and or using the Presenter mode. Try them out and get things all set up before your talk.
- Change the theme: Preferences → Appearance & Behavior → Appearance. Here you can change the theme between Default and Darcula. Depending on the lighting in the room and the audience’ preference, you might prefer Default or Darcula.
- Increase the font size:
- Preferences → Appearance & Behavior → Appearance, Override default fonts by. You will see the font size change for the file name headings and breadcrumbs in Android Studio.
- Preferences → Editor → Colors & Fonts → Font. Click on “Save As”, enter a new scheme name and increase font size here. Now you will see the font size change in the Editor window. If you on a Mac you can simply zoom in/out with two fingers on the trackpad.
3. Use Presenter Mode, View → Enter Presenter Mode.
Launch Android Studio in Project View
By default Android Studio launches all projects in Android View; however most of the time I tend to prefer the Project View because it reflects the actual file hierarchy. So every time I open a project I always have to switch from the default Android view to my preferred Project view. Recently I was very happy to discover that I can set Android Studio to launch in Project view by default. What a time saver! I learned this trick from one of Kelley Shuster’s tweet. So here it is:
- Go to Android Studio → Help → Edit Custom Properties
- Click “yes” if prompted to create a new properties file
- In the idea.properties file, enter studio.projectview=true
- Save and restart Android Studio, and all your projects will now be opened in Project View by default!
protip Edit custom properties of Android Studio to launch Project view by default.
Multiple Android Studio Versions
From Reto Meier’s blog How Often Should You Update Android Studio? I learned that you can have multiple versions of Android Studio installed from different channels (Stable, Beta, Dev and Canary). So I installed both the Stable and Canary versions. I use the Stable channel version for building production release apps when I don’t have time to deal with Android Studio bugs, and use the Canary version for non-critical sample apps or when I’m just playing in Android Studio with some new tools or Android APIs.
Additional Learning Resources
There are lots of great learning resources on the topic of Android Studio.
- There was a great talk Android Studio for Experts from Android Dev Summit 2015. In case you don’t have time to watch that entire video, spend a few minutes to read Reto Meier’s blog (About) 10 Things You (Probably) Didn’t Know You Could do in Android Studio. What I remember most vividly is that clicking on Tab instead of Enter on auto suggests will replace instead of append to the current content. Clicking on Tab will also insert Live Template for example a Toast.
- There are lots more tips on Android Studio from The experts’ Guide to Android development tools at Google I/O 2016.
- Android GDE Sebastiano Poggi has his own series of protips on Android Studio. For example, from his protip #1 Clear App Data Quickly I learned how to use the plugin ADB Idea to clear app data quickly via Android Studio.