Android Annotation

Android注解收集

官方说明

@Nullable
@NonNull

@StringRes
@IdRes
@DrawableRes
@ColorRes
@DimenRes
@InterpolatorRes
@LayoutRes
@AnyRes

@ColorInt

@StringDef
@IntDef

@MainThread
@UiThread
@WorkerThread
@BinderThread
@AnyThread

@IntRange
@FloatRange
@Size

@TargeApi
@RequiresPermission
@RequiresPermission.Read
@RequiresPermission.Write

@Throws

@SdkConstant

@CheckResult
@CallSuper

@Keep

@VisibleForTesting

@RestrictTo

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import android.support.annotation.IntDef
//...
// Define the list of accepted constants and declare the NavigationMode annotation
@Retention(AnnotationRetention.SOURCE)
@IntDef(NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS)
annotation class NavigationMode

// Declare the constants
const val NAVIGATION_MODE_STANDARD = 0
const val NAVIGATION_MODE_LIST = 1
const val NAVIGATION_MODE_TABS = 2

abstract class ActionBar {

    // Decorate the target methods with the annotation
    // Attach the annotation
    @get:NavigationMode
    @setparam:NavigationMode
    abstract var navigationMode: Int

}
1
2
3
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
@RequiresPermission(Manifest.permission.CALL_PHONE)
const val ACTION_CALL = "android.intent.action.CALL"
1
2
@CheckResult(suggest = "#enforcePermission(String,int,int,String)")
abstract fun checkPermission(permission: String, pid: Int, uid: Int): Int
1
2
3
4
// 对public方法或属性进行注解,限制访问
@RestrictTo(RestrictTo.Scope.SUBCLASSES)
@RestrictTo(RestrictTo.Scope.GROUP_ID)
@RestrictTo(RestrictTo.Scope.TESTS)
Annotation
android tools namespace
ml-kit
© 2020 qomg
Powered by hexo | Theme is blank