Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Android Studio Formatted Save

DZone's Guide to

Android Studio Formatted Save

This quick tutorial shows you how to set hotkeys to macros in Android Studio to save time on the commands you use frequently.

· Mobile Zone ·
Free Resource

Before Android Studio was around, many developers (including myself) used Eclipse. In Eclipse, you could set actions to be performed On Save. So whenever you saved, you could tell it to format your code, for example.

When I moved to Android Studio, I missed this feature. I can understand why it was removed, though, since Android Studio constantly saves for you. That way you don’t have to remember to save, it does it for you. You can still save manually if you want, but it’s unnecessary for the most part.

However, I still wanted the ability to format my code, and a few other things. In Android Studio, you can create custom macros and set them to whatever hotkey you want.

To make a custom macro, simply go Edit > Macros > Start Macro Recording and then run whatever commands you want. When you’re done, go back to the same menu and hit Stop Macro Recording and save it as whatever you want. You can see what I run in my formatted save macro below.

commands

Lastly, you’ll probably want to add a shortcut for the macro, so go to Android Studio preferences and search for “macro.” You should find a list of macros that you’ve created, and from there you can set the shortcut you want.

shortcut

Topics:
mobile ,mobile app development ,android ,android studio

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}