使用ButterKnife - lyloou/lou GitHub Wiki
使用ButterKnife
简介
Bind Android views and callbacks to fields and methods.
使用步骤
在project-level的build.gradle
中添加:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
在module-level的build.gradle
中添加:
apply plugin: 'android-apt'
android {
...
}
dependencies {
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
}
注意事项
(在使用V8.2.1
这个版本的时候出现的问题)
如果你的module引用的lib中使用了butterknife
,如果你想要在module中也使用butterknife
,那么在module-level的build.gradle
中需要再次引入butterknife
插件,否则会出现初始化不成功的问题(可以正确引用,但是不生效,具体原因待分析);(也就是说,libs继承关系对butterknife
无效)
小技巧
使用Android Studio的插件ButterKnifeZelezny,可以快速自动生成代码;