17

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.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Vikas Patidar
  • 42,865
  • 22
  • 93
  • 106
  • In `Settings > Editor > Colors & Fonts > Java` you are given a code snippet, you can click on the highlighted variables/classes and are redirected to the corresponding attribute - is there really nothing what matches your case? – yennsarah Oct 29 '15 at 06:38
  • Settings > Editor > Colors & Fonts > Java Save as new template.. Staticfield/method you can edit Foreground and Background ? – Dhinakaran Thennarasu Oct 29 '15 at 06:43
  • @DhinakaranThennarasu That affects only members/constants declared with in class, no changes in members and constants used from static imports from other classes. – Vikas Patidar Oct 29 '15 at 06:54
  • @Amy : Yes there is no attribute in this case. – Vikas Patidar Oct 29 '15 at 06:56
  • 3
    by 'highlighting', do you mean it changes its color to purple? Do you want to keep it black? – khusrav Nov 02 '15 at 11:00
  • @khusrav it's default highlight color for static import related members/constants, and simply I don't want it to be highlighted – Vikas Patidar Nov 02 '15 at 11:21

4 Answers4

9

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.

MatF
  • 1,728
  • 2
  • 14
  • 31
3

"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.

khusrav
  • 5,267
  • 5
  • 27
  • 38
  • My case is different than what you have suggested. it affects only local variables, not the imported. – Vikas Patidar Nov 02 '15 at 11:06
  • @VikasPatidar can you then elaborate a little more? – khusrav Nov 02 '15 at 11:06
  • Does changing the `background` field to white not remove the highlight? – Marko Nov 02 '15 at 11:06
  • @Marko no, it doesn't changes anything for imported static constants or members – Vikas Patidar Nov 02 '15 at 11:08
  • I have an imported constant 'android.support.v4.view.MenuItemCompat#SHOW_AS_ACTION_IF_ROOM' and changed its color to red. – khusrav Nov 02 '15 at 11:10
  • @khusrav did you used static import? – Vikas Patidar Nov 02 '15 at 11:11
  • @VikasPatidar yes. Let me try to prepare a screenshot – khusrav Nov 02 '15 at 11:11
  • 1
    @VikasPatidar khusrav's solution works for me (with import static android.opengl.GLES20.*; constants). Maybe you coluld provide list of items in Colors&Fonts->Java that have non-empty background field? – Dmitrii Z. Nov 02 '15 at 11:13
  • @khusrav I think you have misunderstood the question, I want to stop highlights for used constants/members which are related to static imports. While your screenshot shows static import with different colors. – Vikas Patidar Nov 02 '15 at 11:19
  • @VikasPatidar it shows it like this across the code. So, if you want it to be no different from other code, check off its foreground color. It will affect all the constants, local and imported. Otherwise, don't understand what do you want. – khusrav Nov 02 '15 at 11:36
  • @khusrav Thanks for your quick support, though what you suggested in your answer as well as in comments, I already tried before posting the question. Now I have figured out the problem comes when we use `Add static import for constant or method` using `ALT + ENTER` shortcut key and then Android Studio imports all as bunch imports using *, then all the static constants/members related to that imports becomes highlighted and they remains same unless I don't close and reopen the file. – Vikas Patidar Nov 02 '15 at 18:31
0

I think you only need to use another Scheme (Editor - Colors & Fonts - Java) instead of your current one.

Look at my following screenshots:

Default Scheme:

Default Scheme

Obsidian Scheme:

Obsidian Scheme

Customized Scheme: At Constant (static final field): uncheck "Use inherited attributes", then set Background color

Customized Scheme

Hope this helps!

BNK
  • 23,994
  • 8
  • 77
  • 87
  • I have already used what you suggested, including other themes. The problem comes only when we use Add static import for constant or method which was already being used with fully qualified class names using ALT + ENTER shortcut key and then Android Studio imports all as bunch imports using *, then all the static constants/members related to that imports becomes highlighted and they remains same unless I don't close and reopen the file. I will explain all in another post. – Vikas Patidar Nov 04 '15 at 17:57
0

I really appreciate the efforts of @khusrav & @BKN, indeed after reading both of the answers I'm convinced that these are the same tricks I used even before posting the question.

However the issue is quite simple that Android Studio doesn't stop highlights of static import related members and constants.

The problem comes only when I use Add static import for constant or method which was already being used with fully qualified class names using ALT + ENTER shortcut key and then Android Studio imports all as bunch imports using * or separate import for every method and constant, then all the static constants/members related to that imports becomes highlighted and they remains same unless I don't close and reopen the file.

Here I am adding 4 screenshots really explains the problem and solution.

1) Usual imports with fully qualified names.

enter image description here

2) Importing on demand static using ALT+ENTER.

enter image description here

3) Highlighted static members after imports.

enter image description here

4) Static members after reopening.

enter image description here

In short the highlights only goes after you reopen the files.

Vikas Patidar
  • 42,865
  • 22
  • 93
  • 106