Android工作室"This file is indented with tabs instead of 4 spaces"

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

每当我编辑文件时,Android Studio 中都会弹出一条消息。它说,“这个文件是用制表符而不是 4 个空格缩进的。”我可以单击“确定”或“缩进 4 个空格”并且我知道有一些方法可以更改为制表符(请参阅 this question),但是一直弹出此消息有点烦人。我什至尝试点击“显示设置”,然后点击“使用制表符”,但仍然弹出消息。

为什么总是出现?我该怎么办?

注意:我的 Java 项目是从 Eclipse 导入的。

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.

您可以在下图中看到该选项已选中:

您从 Eclipse 导入的项目使用制表符而不是空格进行缩进。 Android Studio 允许您保持这种代码风格。但是,如果您不想收到提醒,可以执行以下操作之一:

修复

以下任何一项都有效:

  • 取消选中检测并使用现有文件缩进进行编辑设置。

  • 更改 Java 的默认缩进(不仅仅是在通用代码样式页面上)。转到 文件 > 设置 > 编辑器 > 代码样式 > Java。在 制表符和缩进 选项卡上单击“使用制表符”。

  • 将制表符转换为空格。每当出现警告时,只需单击“Indent with 4 spaces”。或者转到 编辑 > 转换缩进 > 到空格

另请参阅:

不确定以前的版本,但使用 Android Studio 2.2.3,Build #AI-145.3537739,构建于 2016 年 12 月 2 日,您可以选择设置 > 编辑器 > 代码风格 允许您不显示通知。

取消勾选,它们就会消失!

Show notifications about detected indents

打开 "Use tab character"(文件 -> 设置 -> 编辑器 -> 代码样式 -> JAVA)。

如果不起作用也这样做, 打开 "show whitespaces"(编辑器 -> 常规 -> 外观)。

如果您使用的是 IntelliJ 终极版,则可以选择 "Show notifications about detected indents"。取消勾选。