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

前端 未结 4 1135
小鲜肉
小鲜肉 2020-12-05 02:29

Android Studio Beta (0.8) has a nifty new feature where it checks that some int parameters are not arbitrary integers, but rather have some properties.

相关标签:
4条回答
  • 2020-12-05 02:55

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

    And technical doc about supporting annotations.

    0 讨论(0)
  • 2020-12-05 03:02

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

    android {
     lintOptions {
        disable "ResourceType"
      }
    }
    
    0 讨论(0)
  • 2020-12-05 03:12

    (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:

    • Video from Google I/O 2014: What's new in Android development tools
    0 讨论(0)
  • 2020-12-05 03:17

    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
    
    0 讨论(0)
提交回复
热议问题