Android Studio Collapse definitions and methods

EditorEditAndroid StudioCollapse

Editor Problem Overview


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?

Editor Solutions


Solution 1 - Editor

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 :)

Solution 2 - Editor

For Windows:

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

For Mac:

  Minimize: COMM + SHFT + '-'
  Expand:   COMM + SHFT + '+'

Solution 3 - Editor

Here's screenshot for quick reference:

enter image description here

Solution 4 - Editor

View -> Tool Windows -> Structure

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

Solution 5 - Editor

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

Solution 6 - Editor

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

Solution 7 - Editor

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

Solution 8 - Editor

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+.

Solution 9 - Editor

This work for me in Windows:

minimize: CTRL + SHIFT + -

expand: CTRL + SHFT + +

Solution 10 - Editor

> Windows 10

ctrl + shift + + to Expand All

ctrl + shift + - to Collapse All

Solution 11 - Editor

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)

Solution 12 - Editor

(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

Solution 13 - Editor

>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

Solution 14 - Editor

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.

Solution 15 - Editor

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.

Solution 16 - Editor

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

Solution 17 - Editor

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDevsinedView Question on Stackoverflow
Solution 1 - Editorfree3domView Answer on Stackoverflow
Solution 2 - EditorFazalView Answer on Stackoverflow
Solution 3 - EditorKhulja Sim SimView Answer on Stackoverflow
Solution 4 - EditorHustenloeserView Answer on Stackoverflow
Solution 5 - EditormarlonpyaView Answer on Stackoverflow
Solution 6 - EditorDyno CrisView Answer on Stackoverflow
Solution 7 - EditorLitvinov NikitaView Answer on Stackoverflow
Solution 8 - EditorcutikoView Answer on Stackoverflow
Solution 9 - EditorlibrushiView Answer on Stackoverflow
Solution 10 - EditorVivek Pratap SinghView Answer on Stackoverflow
Solution 11 - EditorJawad ZebView Answer on Stackoverflow
Solution 12 - Editoruser2768308View Answer on Stackoverflow
Solution 13 - EditorZar E AhmerView Answer on Stackoverflow
Solution 14 - EditorEyyüp AlkışView Answer on Stackoverflow
Solution 15 - EditorKevinView Answer on Stackoverflow
Solution 16 - EditorJose MhlangaView Answer on Stackoverflow
Solution 17 - EditorSuraj VermaView Answer on Stackoverflow