Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop highlights of static import methods/constants in Android Studio?

I am using static imports in Android Studio as:

import static android.opengl.GLES20.*;

But android studio highlighting every static member/constant related to static import in code as.


I've also tried to look for an option in Settings > Editor > Color & Fonts > Java but found nothing about changing color.

like image 393
Vikas Patidar Avatar asked Oct 29 '15 06:10

Vikas Patidar


People also ask

Why static imports are not good?

If you overuse the static import feature, it can make your program unreadable and unmaintainable, polluting its namespace with all the static members you import. Readers of your code (including you, a few months after you wrote it) will not know which class a static member comes from.

Why are static imports bad Java?

by Joshua Bloch.) This is considered bad Java programming practice because when a class implements an interface, it becomes part of the class's public API. Implementation details, such as using the static members of another class, should not leak into public APIs.

How do I import a static method?

In Java, static import concept is introduced in 1.5 version. With the help of static import, we can access the static members of a class directly without class name or any object. For Example: we always use sqrt() method of Math class by using Math class i.e. Math.

Why some imports are static in Java?

Static import is a feature introduced in the Java programming language that allows members (fields and methods) which have been scoped within their container class as public static , to be used in Java code without specifying the class in which the field has been defined.


2 Answers

As your problem is just the highlighting after you used "add on demand static import" and not for the style in general, the solution is pretty simple:

Press Escape. Sometimes you may need to press it twice.

like image 137
MatF Avatar answered Oct 05 '22 11:10

MatF


"Settings > Editor > Color & Fonts > Java", in the Scheme then find 'Constant (static final field)' and choose the color you want.

Upd.: Screenshot

enter image description here

Upd. 2: The answer from MatF is the solution to the actual problem asked about.

like image 3
khusrav Avatar answered Oct 05 '22 12:10

khusrav