Android studio complains when I return a regular int and try to use that int as an input parameter to a Visibility-annotated int. How can I annotate my method so that AS doesn't produce this warning? I see that View has a public @interface "Visibility" but for some weird reason I can't reference android.view.View.Visibility
from my project even if it's public. Why?
My method:
public static int booleanToVisibleOrInvisible(boolean visible) {
return visible ? View.VISIBLE : View.INVISIBLE;
}
What I need:
@android.view.View.Visibility // <- does not compile
public static int booleanToVisibleOrInvisible(boolean visible) {
return visible ? View.VISIBLE : View.INVISIBLE;
}
but for some weird reason I can't reference android.view.View.Visibility from my project even if it's public.
Take a look into the source code, you'll see that this annotation is 'annotated' with the @hide
tag:
/** @hide */
@IntDef({VISIBLE, INVISIBLE, GONE})
@Retention(RetentionPolicy.SOURCE)
public @interface Visibility {}
@hide
tag is used to exclude the annotated package/class/method/etc from the android.jar
file so it's not available at compile time. I doubt you can somehow use this same annotation in your code unless Google engineers remove the @hide
tag from the sources.
You can suppress this warning with //noinspection ResourceType
comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With