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.
In Eclipse I used to do the settings
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
To format the entire Java code of that particular file on save I used to do the below settings in Eclipse
Open preferences-> Java -> Editor -> Save Actions->Check the appropriate options in the dialog
But I don't aware to do the similar settings in Android Studio, can anyone help me to setup this. Thanks in advance.
For Auto Formatting your Java/xml files in Android Studio use following commands:
CTRL + ALT + L
If you are using ubuntu , using this command will Log you out, use :
Shift + CTRL + ALT + L
A popUp will appear : select whole file and Rearrange code and You are done. :)
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:
Ctrl + Alt + O
This is used to find/optimize unused import. If a dialog open select 'Dont show it again' and hit Run.Ctrl + Alt + O
.Ctrl + Alt + L
. This formats your code. (Shift+ctrl+Alt+L
for ubuntu).Ctrl + S
,This saves your file;)Boom, You have now successfully created your Macro, Now just add/assign a shortcut to it:
Ctrl + S
.Ctrl + S
to be your new macro.That's it! your done man. Cheers :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With