问题描述
每当我编辑文件时,我都会在 Android Studio 中弹出一条消息.它说,这个文件用制表符而不是 4 个空格缩进."我可以点击确定"或缩进 4 个空格"而且我知道有多种方法可以更改选项卡(请参阅:
如果您已经尝试过最新的 IntellIJ IDEA 14 EAP 版本,那么您可能已经注意到代码样式设置提供了一个新选项:检测并使用现有文件缩进进行编辑(默认启用.)
这个新选项让 IntelliJ IDEA 检测某些代码样式设置(如使用制表符和缩进大小)在当前编辑动态文件.这意味着即使文件具有代码样式与您当前的设置不同,它们仍将被保留.
所以现在您不必担心丢失文件中的格式特定于您项目中的某些文件,这些文件不同于其他人.
您可以在下图中看到该选项被选中:
您从 Eclipse 导入的项目使用制表符而不是空格来缩进.Android Studio 允许您保持这种代码风格.但是,如果您不想要提醒,您可以执行以下操作之一:
修复
以下任何一种都可以:
取消选中检测并使用现有文件缩进进行编辑设置.
更改 Java 的默认缩进(不仅仅是在通用代码样式页面上).转到 文件 >设置 >编辑器代码风格爪哇.在制表符和缩进选项卡上点击使用制表符".
- 将制表符转换为空格.只需单击缩进 4 个空格"即可.每当警告出现时.或转到编辑>转换缩进到空间.
另见:
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.
Why does it always come up? What can I do about it?
Note: My Java project was imported from Eclipse.
The JetBrains IntelliJ IDEA Blog states:
You can see that option checked in the following image:
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".
- 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?
这篇关于Android Studio“此文件使用制表符而不是4个空格缩进"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!