Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio "This file is indented with tabs instead of 4 spaces"

I keep getting a message popping up in Android Studio whenever I edit a file. It says, "This file is indented with tabs instead of 4 spaces." I can click "OK" or "Indent with 4 spaces" and I know there are ways to change to tabs (see this question), but it is a little annoying to have this message pop up all the time. I even tried clicking "Show Settings" and then "Use tab character" but I still got the message popping up.

enter image description here

Why does it always come up? What can I do about it?

Note: My Java project was imported from Eclipse.

like image 493
Suragch Avatar asked Jun 30 '15 03:06

Suragch


People also ask

How do you change the indent in brackets?

In the lower-right of the status bar you should see an indicator saying "Tab Size." Click the label to toggle to spaces. To change the amount of indent, click the number next to it and type a new value.

Is tab always 4 spaces?

Answer. In most code editors, tabs are not the same as 2 spaces or 4 spaces by default. A tab is stored differently than spaces in the code. Tabs can be seen as a big “jump” in the text, while spaces are always 1 space each.

How do you get rid of multiple lines indentation?

If you're using IDLE, you can use Ctrl+] to indent and Ctrl+[ to unindent.


1 Answers

The JetBrains IntelliJ IDEA Blog states:

If you’ve already tried the latest IntellIJ IDEA 14 EAP build, you might’ve noticed that the Code Style settings offers a new option: Detect and use existing file indents for editing (enabled by default.)

This new option lets IntelliJ IDEA detect certain Code Style settings (such as Use Tab character and Indent size) in the currently edited file on the fly. It means that even if a file has a code style different from your current settings, they will still be preserved.

So now you don’t need to worry about losing the formatting in files that are specific to certain files in your project that differ from the others.

You can see that option checked in the following image:

enter image description here

The project you imported from Eclipse used tabs rather than spaces for indenting. Android Studio allows you to keep this code style. However, if you don't want the reminders, you can do one of the following things:

Fixes

Any of the following will work:

  • Uncheck the Detect and use existing file indents for editing setting.

  • Change your default indenting for Java (not just on the general Code Style page). Go to File > Settings > Editor > Code Style > Java. On the Tabs and Indents tab click "Use tab character".

enter image description here

  • Convert Tabs to Spaces. Just click "Indent with 4 spaces" whenever the warning comes up. Or go to Edit > Convert Indents > To Spaces.

See also:

  • Changing Indentation (docs)
  • Tabs versus spaces—what is the proper indentation character for everything, in every situation, ever?
like image 167
Suragch Avatar answered Oct 25 '22 01:10

Suragch