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

4

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.

Maxie answered 29/10, 2015 at 6:23 Comment(6)
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?Frication
Settings > Editor > Colors & Fonts > Java Save as new template.. Staticfield/method you can edit Foreground and Background ?Hydromedusa
@DhinakaranThennarasu That affects only members/constants declared with in class, no changes in members and constants used from static imports from other classes.Maxie
@Amy : Yes there is no attribute in this case.Maxie
by 'highlighting', do you mean it changes its color to purple? Do you want to keep it black?Thermoluminescent
@Thermoluminescent it's default highlight color for static import related members/constants, and simply I don't want it to be highlightedMaxie
P
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.

Pagel answered 4/11, 2015 at 19:33 Comment(1)
Confirm, the issue turned out to be simple. Double-escape helped.Thermoluminescent
T
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.

Thermoluminescent answered 2/11, 2015 at 11:3 Comment(11)
My case is different than what you have suggested. it affects only local variables, not the imported.Maxie
@VikasPatidar can you then elaborate a little more?Thermoluminescent
Does changing the background field to white not remove the highlight?Abuse
@Abuse no, it doesn't changes anything for imported static constants or membersMaxie
I have an imported constant 'android.support.v4.view.MenuItemCompat#SHOW_AS_ACTION_IF_ROOM' and changed its color to red.Thermoluminescent
@Thermoluminescent did you used static import?Maxie
@VikasPatidar yes. Let me try to prepare a screenshotThermoluminescent
@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?Menstrual
@Thermoluminescent 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.Maxie
@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.Thermoluminescent
@Thermoluminescent 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.Maxie
R
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!

Ridenour answered 3/11, 2015 at 4:3 Comment(1)
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.Maxie
M
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.

Maxie answered 4/11, 2015 at 19:19 Comment(3)
You don't have to reopen the file. See my answer for a quicker solution.Pagel
Actualy I really want to highlight this case. Is there any?Dehaven
I didn't get what actually you want? Please explainMaxie

© 2022 - 2024 — McMap. All rights reserved.