Tíbó
Tíbó

Reputation: 1218

Android Studio code style for comments

I'm writing code guidelines for some of our projects on Android. I'd actually like to facilitate this by using Android Studio code style preferences. I'm almost done setting parameters there: Android Studio->Preferences->Editor->Code Style->Java.

One thing I'm missing is that we want comments to be formatted like this :

// a useful comment

Instead of :

//a useful comment

How do I tell Android Studio to but a space between slashes and the text in the comment? Thanks!

Upvotes: 7

Views: 2898

Answers (4)

Hai Hack
Hai Hack

Reputation: 1018

For anyone who doesn't know

Under Code Style → Java/Kotlin→Code generation

Uncheck Line comment at first column

Check Add a space at line comment start, then Enforce on reformat

It should be okay

enter image description here

Upvotes: 0

Joshua
Joshua

Reputation: 356

I have just solved this problem.

I think you can find Code Style -> Java -> Code Generation
There is a Comment Code and select the Add a space at comment start
I think your problem can be solved.

Upvotes: 1

Tree
Tree

Reputation: 31361

If you press CTRL / or CMD / it will put // at the beginning of the line and the comment will be properly indented.

//        comment with two indents

For this to work Comment at first column must be checked in Editor->CodeStyle->Java->Wrapping and Braces->Keep when reformatting like mentioned in another answer.

screenshot

If you want to write multiline comment you can use CTRL SHIFT / or CMD SHIFT / That way when you go into new line, you will have one space after the comment start

    /*
    * there is space before this*/

Upvotes: 2

guna a
guna a

Reputation: 49

You can do it under the tab Wrapping and Braces.

Upvotes: 0

Related Questions