2

In Eclipse one can indent code by Ctrl+shift+F Unfortunately, this does not work in Android Studio.

Is there any opportunity doing this in Android-Studio?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Blnpwr
  • 1,793
  • 4
  • 22
  • 43

3 Answers3

6

You have pretty much two options:

  1. Change keymapping from Settings -> Keymap, and select Eclipse keymap

  2. You can use the default which is CTRL + ALT + L

EDIT: people in the comments are suggesting that CTRL + ALT + WinKey+Lis the correct binding for Linux but the document of IDEA tells you that it's the same with Windows mapping: https://resources.jetbrains.com/assets/products/intellij-idea/IntelliJIDEA_ReferenceCard.pdf

EDIT #2: I sniffed some more info and found this answer https://askubuntu.com/a/412060. So after all you might get in trouble with the default keymapping when using, lets say Ubuntu, so watch out :)

Community
  • 1
  • 1
vilpe89
  • 4,656
  • 1
  • 29
  • 36
3

On Mac, CMD + ALT + L will reformat your code for you in your current open file for both your Java files and XML files

On Windows I assume it will be CTRL + ALT + L

MichaelStoddart
  • 5,571
  • 4
  • 27
  • 49
  • It's not refactor, it's reformat. Refactor means structural changes to code. – vilpe89 Dec 20 '16 at 14:48
  • Edited my answer accordingly! Thanks @vilpe89 – MichaelStoddart Dec 20 '16 at 14:52
  • Does this work on Ubuntu either? I just have seen the comment of Gudin, saying that Ctrl+ALt+L could lock screen on linux, therefore for Linux it is Ctrl+Alt+Win+L, guess. Would be nice if you edit your answer for linux users either. Thank you. – Blnpwr Dec 20 '16 at 14:52
  • when we suggest an edit who ignore it and post that suggestion as own one without a single chage don't even deserve that edit – Charuක Dec 20 '16 at 14:56
  • You took me wrong. I appreciate this answer and marked it as an accepted answer. It is just for the future when someone has the same problem. – Blnpwr Dec 20 '16 at 14:57
2

In your file do CTRL + A to select all the code and then CTRL + Alt + L (default shortcut) to re-indent all the code.

Charuක
  • 12,953
  • 5
  • 50
  • 88
Prerak Sola
  • 9,517
  • 7
  • 36
  • 67