Android kotlin 中使用 ButterKnife

Android项目中引入kotlin(略,新建kotlin文件时AS会提示你引入kotlin)

Java中使用ButterKnife:

先在module中添加依赖

implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

这是我一直使用的ButterKnife版本
之后加入快速生成代码的插件


image.png

配置完成后就可以在Java代码的activity中使用了 右击R.layout.xxxx -> Generate -> Butterknife Injection即可


image.png

kotlin 配合 kotterknife使用

在module中添加依赖:(网上的资料说还是要依赖上文的gradle中的配置,这里我是在同一个项目)

    implementation 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT'

在项目的gradle的 allprojects的 repositories 添加:

repositories {
    maven { url "[https://oss.sonatype.org/content/repositories/snapshots](https://oss.sonatype.org/content/repositories/snapshots)"}
    mavenCentral()
}

最后添加kotterknife插件


image.png

配置完成后在kotlin的activity的R.layout.xxx上右击 即可使用


image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容