Last Updated : 23 Jul, 2025
Code formatting is very important when you are building an Android application. This will help you to organize your code properly and to maintain your code to make it easily readable. Below is a list of purposes of having a standard coding format.
Purposes of Having Coding Standards
In this article, we will take a look at different ways to format the code in Android Studio. We are going to discuss three different methods with the help of which we can format the code in our Android Studio.
In this method, we simply have to navigate to the file in which we have to format our code. After opening the file we have to simply press the shortcut key as Ctrl+Alt+L to reformat the code in your file. With this key, the code in your file will be rearranged according to the code standards. You can get to see below image 1 in which our code is not formatted properly and after pressing this shortcut key our code will be formatted as shown in the second image.
Unformatted code which we have written. Formatted code which we get after pressing Ctrl+Alt+LShortcut keys for different Operating Systems
Operating System
Shortcut key
Windows Ctrl+Alt+L Mac OS Option+Cmd+L Linux Ctrl+Shift+Alt+L Method 2: Formatting a code from MenuBarIn this method, we will rearrange our code from the Menu Bar. To format our code navigate to the file in which we have to format our code and inside that file. Navigate to the top bar and click on the Code option and inside that option click on Reformat code option which is shown in the below screenshot.
After clicking on this option your code will be formatted as shown in the above screenshotMethod 3: By using different shortcut keys for formatting our codeNote: This method will be similar for all the operating systems
Navigate to the file in which we have to format our code and then click on the shortcut key as Ctrl+Shift+Alt+L after clicking this key you will get to see the below dialog on your screen. Select the formatting options and your code will be formatted and rearranged according to selected options. The options present inside this dialog box is explained below.
After selecting the option on this dialog make sure to run it to format your codeShortcut keys for different Operating System
Operating System Shortcut key Windows Ctrl+Shift+Alt+L Mac OS Cmd+Alt+L Linux Ctrl+Super+Alt+LRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4