android中有标记可见性变量的注释吗?

问题描述 投票:0回答:1

View.VISIBLE
和类似的静态可见性变量的数据类型为
int
,我需要禁止将此变量的值设置为“0”,“1”等。此变量应仅采用
View.VISIBLE
和类似值。例如:

    data class State(
        @SomeAnnotation val buttonVisibility: Int  
    )

    val state = State(0) // Compilation error
    val state = State(View.GONE) // Okay
java android kotlin view annotations
1个回答
1
投票

知道 android.view.View.Visibility 标记有 @hide 并且不能在代码中使用,可能唯一的解决方案是创建自定义枚举,例如

enum class Visibility(val value: Int) {
    VISIBLE(View.VISIBLE), 
    INVISIBLE(View.INVISIBLE), 
    GONE(View.GONE)
}

并在 State 类中使用它

data class State(val buttonVisibility: Visibility)
© www.soinside.com 2019 - 2024. All rights reserved.