版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
1.空检查@Nullable
、@NonNull
变量、参数或者返回值的空值检测
@Nullness
表示可以为null;@NonNull
表示不可以为null@Nullable
标记的方法,如果返回值不进行null的检查,会出现警告
2.资源注解
- @StringRes:包含 R.string 引用
- @IntegerRes:R.integer 类型资源。
- @AnimatorRes:R.animator 类型资源。
- @AnimRes:R.anim 类型资源。
- @ArrayRes:R.array 类型资源。
- @AttrRes:R.attr 类型资源。
- @BoolRes:R.bool 类型资源。
- @ColorInt:某个参数必须为颜色整型
- @ColorRes:R.color 类型资源。
- @DimenRes:R.dimen 类型资源。
- @DrawableRes:R.drawable 类型资源。
- @FractionRes:R.fraction 类型资源。(百分比)
- @IdRes:R.id 类型资源。
- @InterpolatorRes:R.interpolator 类型资源。(插值器)
- @LayoutRes:R.layout 类型资源。
- @MenuRes:R.menu 类型资源。
- @PluralsRes:R.plurals 类型资源。(复数)
- @RawRes:R.raw 类型资源。
- @StyleableRes:R.styleable 类型资源。
- @StyleRes:R.style 类型资源。
- @TransitionRes: R.transition 类型资源。
- @XmlRes:R.xml 类型资源。
3.线程注解
- @MainThread
- @UiThread
- @WorkerThread
- @BinderThread
- @AnyThread
4.值约束注解
- @IntRange(from=0,to=255) int alpha :类型为[1,2255]范围内的int值域
- @FloatRange(from=0.0, to=1.0) :float alpha
- @Size(min=2): 最小大小为2
- @Size(max=2):最大大小 (例如 )
- @Size(multiple=2) :表示大小必须为此倍数的数字
5.权限注解
@RequiresPermission(Manifest.permission.SET_WALLPAPER)
public void aa()