Damian Walker

Personal Web Pages

Indentation in Android Studio

Android code style settings

Thursday, 18th June 2015

Since I last blogged, I made a lot of progress with just about no real road blocks. I'm implementing an Android implementation of Steve Meyers' excellent BoxOff puzzle as my first project. One niggling thing has been annoying me as I code, though.

I like my code indented by four spaces. I like short lines, so that if necessary I can print the code out on a printer or casually browse through it on an 80-column screen or terminal window. Android's default indentation, especially for lines which are split, is way too generous to fit within these limits.

There's a setting for this, in File -> Settings... -> Editor -> Code Style, called "Continuation indent." I'd been setting this for a while and was ignored. Android Studio's editor was still "helpfully" indenting my lines far more than I wanted.

Only today I noticed that "Code Style" itself has a sub-menu. And one of the items on that sub-menu is "Java". Silly me. Setting the continuation indent in the Java section makes the editor to behave how I want it to.

Another little habit I picked up from somewhere is using a space before an open parenthesis or square bracket. Along with using commas after spaces, I think this spacing makes the code look much more readable. Now if only I can persuade Android Studio to stop removing these spaces I'll be truly happy...