Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 278
Tíbó Avatar asked Oct 19 '22 06:10

Tíbó


2 Answers

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*/
like image 89
Tree Avatar answered Oct 29 '22 18:10

Tree


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.

like image 23
Joshua Avatar answered Oct 29 '22 19:10

Joshua