An open API service indexing awesome lists of open source software.

https://github.com/devzwy/vbs

kotlin常用扩展函数
https://github.com/devzwy/vbs

Last synced: about 1 year ago
JSON representation

kotlin常用扩展函数

Awesome Lists containing this project

README

          

# ViewBinding

kotlin常用扩展函数 自用

不定时更新

```kotlin
//toast 支持 view/context
toastShort("")
toastLong("")
//支持 view/context
dp2px(100)
px2dp(100)
//复制文本到剪切板
copyToClipboard("1234567")
//读取颜色
getColorFromRes(R.color.black)
//对象转json字符串
TestData().toJson()
//json字符串转对象
"{...}".toObject(TestData::class.java).a
//json字符串转集合-文本集合
"[...]".toObjectArray().get(0)
//json字符串转集合-对象集合
"[{},{}]".toObjectArray().get(0)
//减少if过程
isVisibility.yes {
//true
this.visibility = View.VISIBLE
}.otherwise {
//false
this.visibility = if (occupy == true) View.INVISIBLE else View.GONE
}

//减少if过程
isVisibility.no {
//false
this.visibility = View.VISIBLE
}.otherwise {
//true
this.visibility = if (occupy == true) View.INVISIBLE else View.GONE
}

```

```xml

```