https://github.com/devzwy/vbs
kotlin常用扩展函数
https://github.com/devzwy/vbs
Last synced: about 1 year ago
JSON representation
kotlin常用扩展函数
- Host: GitHub
- URL: https://github.com/devzwy/vbs
- Owner: devzwy
- Created: 2022-06-05T01:15:55.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-05T11:58:53.000Z (about 4 years ago)
- Last Synced: 2025-02-10T02:24:23.653Z (over 1 year ago)
- Language: Kotlin
- Size: 396 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
```