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.
Join the DZone community and get the full member experience.Join For Free
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.
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.
Published at DZone with permission of Pierce Zaifman, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.