github网址:https://github.com/JakeWharton/butterknife 中有详细配置
app的build.gradle
android {
...
// Butterknife requires Java 8. compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { implementation 'com.jakewharton:butterknife:10.2.1' annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1' }
project中的build.gradle
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.1' } }
自己在android studio中安装一个插件就可以右键生成
Activity中使用 ButterKnife.bind(this);
fragment中使用 bind = ButterKnife.bind(this, view);//this不能变···写死就完了
adapter中使用 在viewholder中使用
public ViewHolder(View view) {
ButterKnife.bind(this, view);
}