Reputation: 18068
I want to format code in a freshly created Android application.
I messed up the code in this manner:
private static final
int AUTO_HIDE_DELAY_MILLIS
= 3000;
I want to format it with Ctrl + Alt + L, but it is not repairing the code. I use Windows 8.1.
Upvotes: 49
Views: 87158
Reputation: 21
Alt + Ctrl + Shift + L is the shortcut key for arranging the code in Ubuntu (Android Studio).
Upvotes: 2
Reputation: 86
At least on my Android Studio version, "keep when formatting - line breaks" was enabled by default. So you need to go to
Preferences → Editor → Code Style → Java and disable that checkbox (see the below screenshot).
Upvotes: 6
Reputation: 23787
In Android Studio (on the Mac), I select the code chunk, and then select the Code menu item and click Auto-Indent Lines.
See screenshot:
Shortcut key (on Mac) is Ctrl + Alt + I.
Upvotes: 12
Reputation: 1722
If you want to:
There isn't any need for them to be capital letters. This is just for the example.
Upvotes: 43
Reputation: 26814
Just right-click on the project or directory, and select Reformat Code
Upvotes: 54
Reputation: 18978
First you will need to configure how your code is formatted. This can be done by going to
[Main Menu]
-> File
-> Settings
then go to
(Project Settings)
-> Code Style
-> Java
In this area you can define all the formatting rules that you would like to apply to your code.
Now you should check (or change) the keyboard shortcut for reformatting code by going to
[Main Menu]
-> File
-> Settings
then go to
(IDE Settings)
-> Keymap
Just type Reformat Code
into the search box at the top right to find it.
Once this is done, highlight the code you want to reformat and use the keyboard shortcut to reformat your code based on the rules you defined.
Upvotes: 38