Android Studio's “expected resource of type” checks?

不想你离开。 提交于 2019-11-27 19:02:48
matiash

(Thanks to @CommonsWare for the heads up).

There are Java annotations to support these checks in your own code. They can all be found in the android.support.annotations package:

  • IdRes
  • DrawableRes
  • LayoutRes
  • StringRes
  • &c

In this case, for example, I could use:

private void mySetContentView(@LayoutRes int resourceId) {
    setContentView(resourceId);
}

and Android Studio will check that the provided resource id is indeed for a layout.

Moreover, these annotations are exported, so they can be especially useful when designing a library.

Sources:

This are all Annotations:

@AnimatorRes
@AnimRes
@AnyRes
@ArrayRes
@AttrRes
@BoolRes
@ColorRes
@DimenRes
@DrawableRes
@FractionRes
@IdRes
@IntDef
@IntegerRes
@InterpolatorRes
@LayoutRes
@MenuRes
@NonNull
@Nullable
@PluralsRes
@RawRes
@StringDef
@StringRes
@StyleableRes
@StyleRes
@XmlRes

Try this answer: Its working... Put this code into your build.gradle

android {
 lintOptions {
    disable "ResourceType"
  }
}

All annotations, that you can use with android.support.annotation you can find here.

And technical doc about supporting annotations.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!