Android Studio 2.1.1 using tabs, not spaces, even though tabs are not checked in Settings
Asked Answered
T

4

6

When editing Java files, if I'm at the end of the line and I type the Enter key, it starts the next line properly indented 4 columns, to match the line above. That's OK but it's indenting with a tab, not spaces, even though in File>Settings>Editor>Java>Tabs and Indents the checkbox for Use tab character is unchecked, and always has been.

If I just type the tab key I also get a tab, not spaces.

I never want to use tab characters; I always want to use spaces. I don't have this problem in Eclipse or Microsoft Visual Studio so it's not some system setting for my PC. Is there some other setting in Android Studio for this?

Edit: I tried the suggestion that Omar Al Halabi (below) made and it didn't work but while testing it I noticed something interesting: This tab problem seems to mainly apply to the beginning of the line, i.e., if I type Enter on the previous line, it immediately tabs over to the first indent position on the following line, using real tabs, not spaces. On the other hand if I'm typing some text on an existing line, once I've typed a little text, if I hit tab, it then tabs over using spaces.

Thunderpeal answered 1/6, 2016 at 19:59 Comment(2)
Could be "Editor -> Code Style -> Indents Detection". "Detect and use existing file indents for editing" which will use tabs if the file you're editing already uses them.Adame
See my other question: link which may be related.Thunderpeal
D
5

hope this helps,

check Use Tab Character,

give all that values to zero than you not get space on enter in java code, like in below image,

one more thing is you have to change your code format settings or may need to disable it

enter image description here

Douglassdougy answered 5/6, 2016 at 8:31 Comment(1)
I can't quite parse your line beginning with "give all that values to zero" but the settings in your screen shot are what I have. Unlike the sample code on the right, my code does, in fact, have indenting but that's because I've manually added spaces to replace tabs. But I think the problem I'm seeing is a manifestation of an automatic indenting problem described here: linkThunderpeal
K
2

This is not an answer, but I don't have enough reputation points to post my questions as a comment.
- Is this issue happening in all your Android Studio projects?
- Are you using the Default scheme for the general File->Settings->Editor->Code Style and also for the Java Code Style?
- Have you tried making a new Java Code Style scheme at the Project level for just one project as a test?

EDIT: This is a brute-force/shotgun approach.

  1. Rename your \Users\<username>\.AndroidStudio2.1 directory (e.g., .AndroidStudio2.1_orig)
  2. Open Android Studio and force it to use the default settings by choosing the "I do not have a previous version of Studio or I do not want to import my settings" option when the "Complete Installation" dialog window appears.
  3. Run a recursive 'diff' between the new and old .AndroidStudio2.1 directories to find any changes you've made to the default settings so you can re-apply them. The settings are kept in XML files so they are human-readable. Keep an eye out for any differences that may affect Android Studio use of tabs & spaces, because those might be the source of the problem.

If this does not work, then you may have to re-install Android Studio.

Kithara answered 5/6, 2016 at 0:8 Comment(0)
A
1

Try opening Settings->Editor->Code Style->Java. Check "Use tab character". Click OK.

Then go to File->Invalidate Caches\Restart -> Invalidate and Restart.

Then, again, go to Settings->Editor->Code Style->Java. Now uncheck "Use tab character" and hit OK.

If it still doesn't work change tab size and indent and then restore them back if you want.

Azaria answered 1/6, 2016 at 20:35 Comment(0)
T
1

The IDE tries to position the lines as if they belong to the same block. Also very likely you had used the tabs on the previous line. You can try to deactivate Detect and use Existing file indents for editing enter image description here

Trigg answered 10/6, 2016 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.