172

How can I collapse all definitions and methods within the Android Studio editor?

Visual Studio has that option on Edit-->Outlining, but I cannot find a similar feature in Android Studio. I am sure that this feature exists.

How can I access Android Studio's outlining feature?

2
  • possible duplicate of Android code folding the Switch block
    – cutiko
    Sep 2, 2015 at 17:59
  • I use "File => Settings => Editor => Gerneral => Code Folding => Collapse by default => Method bodies". For me it's the best overview.
    – Martin
    Sep 18, 2015 at 7:31

19 Answers 19

257

It is called Folding in Android Studio.

First make sure it is enabled in config (it should be by default). Go to File -> Settings, then under the IDE Settings area find Editor -> General -> Code Folding, check the Show code folding outline.

To collapse/expand items use the Code -> Folding menu.

Edit:
To customize the keyboard shortcuts for these open Settings (File -> Settings) then select Keymap under IDE Settings. Now type folding into the search box (top right). Setup the keyboard shortcut for the various folding actions :)

5
  • 48
    Shortcut Expand: Cmd + '+' Collapse: Cmd + '-'
    – Priebe
    May 13, 2014 at 11:10
  • 64
    shortcut expand all: shift + cmd + '+' (collapse all: shift + cmd + '-')
    – tmr
    Oct 16, 2014 at 17:01
  • 44
    For Windows shortcut expand: ctrl + '+' (collapse: ctrl + '-') shortcut expand all: shift + ctrl + '+' (collapse all: shift + ctrl + '-')
    – Rafael
    Dec 18, 2014 at 4:31
  • 2
    In the version of Android Studio I have installed on my Mac, the Shortcut keys were Cmd + Shift + '+' to expand and Cmd + Shift + '-' to collapse. This is slightly different than @Priebe's comment above.
    – benhorgen
    Jul 27, 2019 at 14:35
  • what if i want to save that folding for future and adjust whenever i re-open that file? Sep 23, 2020 at 7:50
234

For Windows:

  Minimize: CTRL + SHFT + '-'
  Expand:   CTRL + SHFT + '+'

For Mac:

  Minimize: COMM + SHFT + '-'
  Expand:   COMM + SHFT + '+'
3
  • 8
    This works with Linux as well. And use Cmd rather than Ctrl for Mac Jun 10, 2015 at 16:37
  • thanks... quick clear precise answer without the need to dig through remarks on how to make it even better by playing with shortcuts keys
    – me_
    Feb 19, 2022 at 11:12
  • so precise answer I wish I could give you an award you like Reddit for such simple answer Jun 9, 2022 at 11:36
52

Here's screenshot for quick reference:

enter image description here

1
  • 2
    well done. people can pick up once again from this reference even if they forget shortcut keys some day
    – ashubuntu
    Nov 1, 2016 at 5:35
12

View -> Tool Windows -> Structure

It's the equivalent to outline in eclipse. It gives you a far better overview of the class than folding.

0
11

my macbookpro

shift + cmd + ¡ (character or button before delete) Expand All

shift + cmd + ' (character or button after zero) Collapse All

windows

ctrl + shift + + Expand All

ctrl + shift + - Collapse All

0
10

If you want turn off all collapsing you need uncheck all fields in the Settings > Editor > General > Code Folding

enter image description here

Also you can use hot keys

ctrl + shift + + — expand code blocks

ctrl + shift + - — collapse code blocks

10

Windows:
Collapse: ctrl + shift + Numpad-
Expand: ctrl + shift + Numpad+

7

This is valid for windows users:

  1. Select a bunch of code, then press ctrl+.. This folds your block
  2. Then to remove the folding, move to the first line where the fold starts. Don't select the code, just click in that first line, and again press ctrl+.
0
5

This work for me in Windows:

minimize: CTRL + SHIFT + -

expand: CTRL + SHFT + +

1
4

Windows 10

ctrl + shift + + to Expand All

ctrl + shift + - to Collapse All

4

What if i want to save that folding for future and adjust whenever i re-open that file?

Step 1: We use custom folding

Specify custom folding with comment //region for start and //endregion for end

//region anything that you want to write (you can even leave it blank)
...
//endregion 

Step 2:

Go to Settings >> Editor >> General >> Code Folding >> Untick everything >> 'Tick Custom Folding Regions' & 'Tick Show Code Folding Outline' >> Apply >> Ok

Screenshot: https://i.stack.imgur.com/sGuce.png

Step 3:

Restart Android Studio. You will see that the demarcated region has been collapsed.

2

Here are some helpful shortcuts for folding stuff.

  1. Select Some Code And Press Ctrl + Alt + T to auto Insert Region folding around the code
  2. To Collapse Specific lines of Code, Select the code and Press Ctrl + .(dot/full stop) & Same for the reverse i.e. expand again
  3. To collapse All method bodies/ if conditions etc etc Press Ctrl + Shift + -(hyphen)
  4. To Expand All Press Ctrl + Shift + +(plus)
1

(for windows)

If you are talking about editor fold just like fcom + tab in netbeans

ctrl + alt+ t and then add desired text in the desc block

1

New Android Studio come up with a lot of new functions. These are the commands you can use to fold different type of code.

enter image description here

1

I had this issue too. I figured out to click gear button where right top of project menu section. Then I unselected Show members option.

1

For Mac you can use cmd + shift + -(hyphen/minus) to fold and to unfold every thing use cmd + shift + +

1

For commenting methods separately, do code folding recursively with ctrl + alt + -

1

The simplest way I know to collapse the methods is to use the command to collapse all and then the command to expand recursively

like this: crtl+shift+- then crtl++.

you can press crtl+shift+-, release shift then click + for convenience.

0

Optionally to collapse single method inside class rather than all methods @once use cmd and - on Mac Cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.