For auto formatting your Java/XML files in Android Studio, use following commands:
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 a macro. Follow these steps:
In Android Studio, open any of your source code files.
Press Ctrl + Alt + O This is used to find/optimize unused import.
If a dialog open select "Don't show it again" and hit Run.
Go to Edit > Macros > Start Macro Recording.
Press Ctrl + Alt + O.
Press Ctrl + Alt + L. This formats your code. (Shift+Ctrl+Alt+L for Ubuntu).
Press Ctrl + S. This saves your file;)
Go to Edit > Macros > Stop Macro Recording.
Save this created macro with a name, for instance: “Auto Formatting".
Boom, you have now successfully created your macro. Now just add/assign a shortcut to it:
Open Preferences.
Search in the left bar for Keymap.
In the right hand pane, click in the search bar and type the name of your saved macro ("Auto Formatting".)
Double click on your item. There might be two, it doesn’t matter which one you click on.
Click Add Keyboard Shortcut.
Set your keyboard shortcut to Ctrl + S.
Finally, confirm overriding Ctrl + S to be your new macro.