在项目的project的build.gradle(Module:app)文件中添加
implementation "com.jakewharton:butterknife:10.0.0"
androidTestImplementation "com.jakewharton:butterknife-compiler:10.0.0"
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
由于使用了java8的新特性,故需要在build.gradle(Module:app)中配置
android {
...
compileOptions{
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
在Activity中绑定ButterKnife
- 如下
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
-
其他方式
- 下载插件
- 将光标移至如下图所示
- 按快捷键
alt+insert
,出现如下图标,点击即可自动生成
- 下载插件