[英]How to convert tabs to spaces and auto formatting on save in android studio
I would like know the steps for converting tabs to 4 spaces and auto formatting the java code on Save which is similar to eclipse. 我想知道将标签转换为4个空格并在Save上自动格式化java代码的步骤,类似于eclipse。
In Eclipse I used to do the settings 在Eclipse中我曾经做过设置
For Converting tabs to Spaces I used to do the below setting 对于将标签转换为空格我曾经做过以下设置
Open references-> Java->Code style -> Formatter->Create a new profile-> Change the setting from tabs only to Spaces only 打开引用 - > Java->代码样式 - > Formatter->创建新的配置文件 - >仅将选项卡的选项更改为仅限空格
To format the entire Java code of that particular file on save I used to do the below settings in Eclipse 要在保存时格式化该特定文件的整个Java代码,我以前在Eclipse中执行以下设置
Open preferences-> Java -> Editor -> Save Actions->Check the appropriate options in the dialog 打开首选项 - > Java - >编辑器 - >保存操作 - >选中对话框中的相应选项
But I don't aware to do the similar settings in Android Studio, can anyone help me to setup this. 但是我不知道在Android Studio中进行类似的设置,任何人都可以帮我设置它。 Thanks in advance.
提前致谢。
For Auto Formatting your Java/xml files in Android Studio use following commands: 对于在Android Studio中自动格式化Java / xml文件,请使用以下命令:
CTRL + ALT + L
CTRL + ALT + L.
If you are using ubuntu , using this command will Log you out, use : 如果您使用的是ubuntu,使用此命令将退出,请使用:
Shift + CTRL + ALT + L
Shift + CTRL + ALT + L.
A popUp will appear : select whole file and Rearrange code and You are done. 将出现一个popUp:选择整个文件并重新排列代码,您就完成了。 :)
:)
Update : 更新:
As you are looking for a single point to go with your work as eclipse
did, there is no such built in functionality in Android studio
but it gives you the ability to do it through Macro
, Follow these steps: 正如您正在寻找与
eclipse
一样的单点工作, Android studio
没有这样的内置功能,但它使您能够通过Macro
执行此操作,请按照下列步骤操作:
Ctrl + Alt + O
This is used to find/optimize unused import. Ctrl + Alt + O
这用于查找/优化未使用的导入。 If a dialog open select 'Dont show it again' and hit Run. Ctrl + Alt + O
. Ctrl + Alt + O
Ctrl + Alt + L
. Ctrl + Alt + L
This formats your code. Shift+ctrl+Alt+L
for ubuntu). Shift+ctrl+Alt+L
)。 Ctrl + S
,This saves your file;) Ctrl + S
,这将保存您的文件;) Boom, You have now successfully created your Macro, Now just add/assign a shortcut to it: Boom,您现在已经成功创建了宏,现在只需添加/指定它的快捷方式:
Ctrl + S
. Ctrl + S
Ctrl + S
to be your new macro. Ctrl + S
作为新宏。 That's it! 而已! your done man.
你做完的男人。 Cheers :)
干杯:)
Type in spac
in the search panel of the settings view. 在设置视图的搜索面板中键入
spac
。
Here you will find a shortcut to Editor -> Code Style -> Java -> Tabs and Indents -> Use tab character
在这里,您可以找到
Editor -> Code Style -> Java -> Tabs and Indents -> Use tab character
的快捷方式
Simply CTRL + ALT + L
只需
CTRL + ALT + L
In the former replay just replace 在前重播只是替换
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.