Java 如何在 Android Studio 中修复“组织导入”以进行静态导入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20452178/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix "Organize Imports" in Android Studio for static imports
提问by Adam Hoddinott
I'm using version 0.3.7 of Android Studio, and I'm trying out OpenGL ES programming. This requires a lot of imports from such classes as "android.opengl.GLES20"
我正在使用 Android Studio 0.3.7 版,并且正在尝试 OpenGL ES 编程。这需要从诸如“android.opengl.GLES20”之类的类中进行大量导入
Instead of auto importing GLES20 and accessing for example, the GL_COMPILE_STATUS variable like so:
例如,不是自动导入 GLES20 并访问 GL_COMPILE_STATUS 变量,如下所示:
glGetShaderiv(shaderObjectID, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
I'd rather type in GL_COMPILE_STATUS and have it auto import the following:
我宁愿输入 GL_COMPILE_STATUS 并让它自动导入以下内容:
import static android.opengl.GLES20.GL_COMPILE_STATUS;
...
glGetShaderiv(shaderObjectID, GL_COMPILE_STATUS, compileStatus, 0);
And have the above import found as I type in GL_COMPILE_STATUS.
并在我输入 GL_COMPILE_STATUS 时找到上述导入。
But the current system will not know that GL_COMPILE_STATUS comes from the GLES20 class. So my question is this, is there a way to assist the organize imports functionality in Android Studio for finding these variable? I'd like to keep my code to a minimum, and having to write GLES20. in front of everything is a little off putting - and I won't use a wildcard import as I consider that bad practice.
但是当前系统不会知道 GL_COMPILE_STATUS 来自 GLES20 类。所以我的问题是,有没有办法帮助 Android Studio 中的组织导入功能找到这些变量?我想将我的代码保持在最低限度,并且必须编写 GLES20。在一切面前都有些过时 - 我不会使用通配符导入,因为我认为这是不好的做法。
回答by bruThaler
The answers of this postwill help you.
这篇文章的答案会对你有所帮助。
- set the packages you want import in
Settings -> Code Style -> Java -> Imports
- press
ctrl+space two times
and thenalt + enter
to import it statically without full qualifier.
- 设置要导入的包
Settings -> Code Style -> Java -> Imports
- 按
ctrl+space two times
,然后alt + enter
在没有完整限定符的情况下静态导入它。