|
| 1 | +# ViewBindingKTX |
| 2 | + |
| 3 | +[](https://www.jitpack.io/#DylanCaiCoding/ViewBindingKTX) |
| 4 | +[](https://github.com/DylanCaiCoding/ViewBindingKtx/blob/master/LICENSE) |
| 5 | +[](https://github.com/DylanCaiCoding/ViewBindingKTX) |
| 6 | + |
| 7 | +[ViewBinding](https://developer.android.com/topic/libraries/view-binding) 相对于 Kotlin synthetics、ButterKnife、findViewById,能减少 id 写错或类型写错导致的异常,官方和 JakeWharton 都推荐使用。但是 ViewBinding 直接使用会有点繁琐,所以本库能**帮助你在各种使用场景用尽可能少的代码来使用 ViewBinding**。 |
| 8 | + |
| 9 | +## Feature |
| 10 | + |
| 11 | +- 支持 Kotlin 和 Java 用法 |
| 12 | +- 支持多种使用反射和不使用反射的用法 |
| 13 | +- 支持封装改造自己的基类,使其用上 ViewBinding |
| 14 | +- 支持 BaseRecyclerViewAdapterHelper |
| 15 | +- 支持 Activity、Fragment、Dialog、Adapter |
| 16 | +- 支持在 Fragment 自动释放绑定类的实例对象 |
| 17 | +- 支持实现自定义组合控件 |
| 18 | +- 支持 TabLayout 实现自定义标签布局 |
| 19 | +- 支持 NavigationView 设置头部控件 |
| 20 | +- 支持 DataBinding 自动设置 lifecycleOwner |
| 21 | + |
| 22 | +## Gradle |
| 23 | + |
| 24 | +在根目录的 build.gradle 添加: |
| 25 | + |
| 26 | +```groovy |
| 27 | +allprojects { |
| 28 | + repositories { |
| 29 | + // ... |
| 30 | + maven { url 'https://www.jitpack.io' } |
| 31 | + } |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +添加配置和依赖: |
| 36 | + |
| 37 | +```groovy |
| 38 | +android { |
| 39 | + buildFeatures { |
| 40 | + viewBinding = true |
| 41 | + } |
| 42 | +} |
| 43 | +
|
| 44 | +dependencies { |
| 45 | + // 以下都是可选,请根据需要进行添加 |
| 46 | + implementation 'com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-ktx:1.2.6' |
| 47 | + implementation 'com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-nonreflection-ktx:1.2.6' |
| 48 | + implementation 'com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-base:1.2.6' |
| 49 | + implementation 'com.github.DylanCaiCoding.ViewBindingKTX:viewbinding-brvah:1.2.6' |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +## 作者其它的库 |
| 54 | + |
| 55 | +| 库 | 简介 | |
| 56 | +| ------------------------------------------------------------ | ---------------------------------------------- | |
| 57 | +| [Longan](https://github.com/DylanCaiCoding/Longan) | 简化 Android 开发的 Kotlin 工具类集合 | |
| 58 | +| [LoadingStateView](https://github.com/DylanCaiCoding/LoadingStateView) | 深度解耦标题栏或加载中、加载失败、无数据等视图 | |
| 59 | +| [MMKV-KTX](https://github.com/DylanCaiCoding/MMKV-KTX) | 用属性委托的方式使用 MMKV | |
| 60 | +| [ActivityResultLauncher](https://github.com/DylanCaiCoding/ActivityResultLauncher) | 优雅地替代 `startActivityForResult()` | |
| 61 | + |
| 62 | +## License |
| 63 | + |
| 64 | +``` |
| 65 | +Copyright (C) 2020. Dylan Cai |
| 66 | +
|
| 67 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 68 | +you may not use this file except in compliance with the License. |
| 69 | +You may obtain a copy of the License at |
| 70 | +
|
| 71 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 72 | +
|
| 73 | +Unless required by applicable law or agreed to in writing, software |
| 74 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 75 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 76 | +See the License for the specific language governing permissions and |
| 77 | +limitations under the License. |
| 78 | +``` |
0 commit comments