Android Studio“导入类"操作添加完全限定名称 [英] Android Studio "Import class" action adds fully qualified name

查看:48
本文介绍了Android Studio“导入类"操作添加完全限定名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Android Studio,当我输入一个我没有导入的类的名称并使用导入类"操作时(使用 ALT-ENTER 或从 CTRL-A 菜单中选择导入类"操作),它只是在我的班级前面添加了包名.

Using Android Studio, when I type the name of a class which I have no import for and use the "Import class" action (using either ALT-ENTER or choosing the "Import class" action from the CTRL-A menu), it simply adds the package name in front of my class.

例如

Intent i = new Intent(Intent.ACTION_SEND);

变成

android.content.Intent i = new Intent(Intent.ACTION_SEND);

有什么办法可以让导入类"操作在默认情况下向文件添加导入,而不是像这样添加完全限定名称?

Is there any way to have the "Import class" action add an import to the file by default instead of adding the fully qualified name like this?

我很确定它曾经像我描述的那样工作.不幸的是,我不知道从那以后发生了什么变化,我想避免重新安装 IDE 并根据我的喜好重新配置所有内容.

I am quite certain it used to work as I describe. Unfortunately, I cannot tell what changed since then and I would like to avoid reinstalling the IDE and reconfiguring everything to my liking.

我的配置

在意图设置中,选中选项导入/用导入替换限定名称".

In the Intentions settings, the option "Imports / Replace Qualified Name with Import" is checked.

在编辑器设置中,动态添加明确导入"选项取消选中,而动态优化导入"选项选中

In the Editor settings, the "Add unambiguous imports on the fly" option is unchecked and "Optimize imports on the fly" is checked

推荐答案

所以我做了同样的事情.我花了一段时间才意识到,但我已经检查了(菜单)文件 --> 设置(在对话框中)代码样式 --> Java --> 导入(选项卡)-->使用完全限定的类名"复选框.

So I did the same thing. It took me a while to realize, but I had checked the (menu) File --> Settings (in dialog) Code Style --> Java --> Imports (tab) --> "Use fully qualified class names" checkbox.

一旦我取消选中,Android studio 就停止完全限定那些(还)没有导入语句的类名.一个例子是当我试图在我的代码中转换为 TextView 并且它自动完全限定它时.现在它只是将其添加为顶部的导入!

As soon as I un-checked that, Android studio stopped fully qualifying the class names that did not (yet) have import statements for. An example was when I was trying to cast to TextView in my code and it auto fully qualified it. Now it just adds it as an import at the top!

注意我使用的是 Android Studio 0.5.9,以防我的复选框路径与您的不同.祝你好运!保罗

Note I am using Android Studio 0.5.9 in case my path to the checkbox is different than yours. Good Luck! Paul

这篇关于Android Studio“导入类"操作添加完全限定名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆