如何修复“组织导入"在 Android Studio 中进行静态导入 [英] How to fix "Organize Imports" in Android Studio for static imports

查看:30
本文介绍了如何修复“组织导入"在 Android Studio 中进行静态导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Android Studio 0.3.7 版,并且正在尝试 OpenGL ES 编程.这需要从诸如android.opengl.GLES20"之类的类中进行大量导入

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"

而不是像这样自动导入 GLES20 并访问 GL_COMPILE_STATUS 变量:

Instead of auto importing GLES20 and accessing for example, the GL_COMPILE_STATUS variable like so:

glGetShaderiv(shaderObjectID, GLES20.GL_COMPILE_STATUS, compileStatus, 0);

我宁愿输入 GL_COMPILE_STATUS 并让它自动导入以下内容:

I'd rather type in GL_COMPILE_STATUS and have it auto import the following:

import static android.opengl.GLES20.GL_COMPILE_STATUS;
...
glGetShaderiv(shaderObjectID, GL_COMPILE_STATUS, compileStatus, 0);

并在我输入 GL_COMPILE_STATUS 时找到上述导入.

And have the above import found as I type in GL_COMPILE_STATUS.

但是当前系统不会知道 GL_COMPILE_STATUS 来自 GLES20 类.所以我的问题是,有没有办法帮助 Android Studio 中的组织导入功能找到这些变量?我想将我的代码保持在最低限度,并且必须编写 GLES20.一切都在前面有点令人反感 - 我不会使用通配符导入,因为我认为这是不好的做法.

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.

推荐答案

这篇文章的答案 会帮助你.

  1. Settings -> 中设置要导入的包代码风格 ->Java ->导入
  2. ctrl+space 两次,然后alt + enter 以静态导入它,没有完整的限定符.
  1. set the packages you want import in Settings -> Code Style -> Java -> Imports
  2. press ctrl+space two times and then alt + enter to import it statically without full qualifier.

这篇关于如何修复“组织导入"在 Android Studio 中进行静态导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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