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

僤鯓⒐⒋嵵緔 提交于 2019-12-23 20:54:39

问题


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) ?


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/26181548/how-to-create-my-own-reformat-code-style-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!