Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android studio format code won't auto break line

tempCanvas.drawArc(cx - mInnerCircleRadius, cy + mInnerCircleRadius,cy + mInnerCircleRadius,cy + mInnerCircleRadius); 

For example, the above code is too long, so I want to break the line at every ,. Eclipse will do it but Android Studio won't break the line when I hit format code. Is there any method to do it?

like image 458
Frank Cheng Avatar asked Nov 28 '14 00:11

Frank Cheng


People also ask

Which is keyboard short cut for auto format code in Android Studio?

Install the Dart plugin (see Editor setup) to get automatic formatting of code in Android Studio and IntelliJ. To automatically format your code in the current source code window, use Cmd+Alt+L (on Mac) or Ctrl+Alt+L (on Windows and Linux).

How can I format Android studio?

After opening the file we have to simply press the shortcut key as Ctrl+Alt+L to reformat the code in your file. With this key, the code in your file will be rearranged according to the code standards.


1 Answers

In Android Studio (and probably any other IDE) you don't break (wrap) lines by , or any other character, you define a maximum line width and set the formatter to ensure the maximum line width is not exceeded.

You do that on File -> Settings on Windows, or in Preferences on Mac OS.

To do this in Android Studio go to

File > Settings > Editor > Code Style 

and set Right margin (columns) to 120 (or the line width you want)

Now go to

File > Settings > Editor > Code Style > Java > Wrapping and Braces (tab) 

and check the checkbox Ensure right margin in not exceeded

Apply the changes and press OK

Now in the editor, to format your code to that line width, press:

Code > Reformat Code...  

Done

In Mac OS instead of File > Settings go to Preferences, follow the same steps.

like image 141
Carlos B. Flores Avatar answered Oct 13 '22 10:10

Carlos B. Flores