user316117
user316117

Reputation: 8281

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

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.

Upvotes: 6

Views: 1076

Answers (4)

KMarto
KMarto

Reputation: 300

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

Upvotes: 1

Irving Moy
Irving Moy

Reputation: 351

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.

Upvotes: 2

Amit Vaghela
Amit Vaghela

Reputation: 22955

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

Upvotes: 5

Omar El Halabi
Omar El Halabi

Reputation: 2128

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.

Upvotes: 1

Related Questions