How to create my own 'Reformat Code' style in Android Studio?
Asked Answered
D

4

10

In Eclipse,(Window -> Preferences -> Java -> Code Style -> Formatter) there was a facility to create my own format style and apply it in the code. Is there a way to do that in Android Studio(for Java code) ?

Donnelldonnelly answered 3/10, 2014 at 15:4 Comment(0)
R
8

To change formatter options go to File | Settings | Code Style | Java

To reformat your code manually, press Ctrl + Alt + L (or using the menu Code | Reformat code...). To reformat the whole source code of your module, just select the module folder first.

More information about reformating source code can be found on the IntelliJ Web Help

Ranique answered 3/10, 2014 at 15:36 Comment(3)
In 'File | Settings | Code Style | Java' there is only 2 options- Default and Project. I need to create a new style other than that. Is it possible ?Donnelldonnelly
If you change your current settings, it will be automatically applied to Project. You can save your current settings anytime as a new scheme by pressing Manage..., selecting Project and then Save as...Ranique
Will you please describe the steps to do it ?Donnelldonnelly
F
1

In Android Studio 3.3.2 (running in Mac OS) "Android Studio" -> "Preferences" -> "Editor" -> "Code Style" -> "Java".

I would be useful to find a way to export/import only code format settings in order to share them between the team.

False answered 27/3, 2019 at 11:23 Comment(0)
B
0

Open global settings/preferences via ⌘, or Android Studio > Prefences.

In the left hand side bar, go to Editor > Code Style.

open the scheme: drop down menu and select Default IDE.

Click the cog menu to the right of the drop down menu and select duplicate....

Then rename your new profile, and change the general settings as well as the settings for each language in the sub menu of Code Style as you see fit.

Then with you new profile selected, reformat your code with + + L

These style are global and can be used in other projects.

Same method applies for Code Cleanup too.

Backdrop answered 23/11, 2019 at 17:23 Comment(0)
S
0

With key combination: Shift + Ctrl + Alt + L you can modify some options of reformatting code as in the screenshot.
Hope this help.

Configure reformatting code

Stoneware answered 23/7, 2023 at 21:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.