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

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

问题描述

使用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.

我的配置

My configuration

在Intentions设置中,选项导入/替换带导入的合格名称是选中

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就停止完全限定没有import语句的类名。一个例子是当我试图转换到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,如果我的路径的复选框不同于你的。祝你好运!
Paul

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“导入类” action添加完全限定名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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