Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 679
user316117 Avatar asked Jun 01 '16 19:06

user316117


2 Answers

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

like image 191
Amit Vaghela Avatar answered Sep 22 '22 02:09

Amit Vaghela


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.

like image 20
Irving Moy Avatar answered Sep 20 '22 02:09

Irving Moy