在项目的build.grade文件中:
buildscript {
repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
//这里配置 apt 供butterknife使用
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
在app的build.grade文件中:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android{...}
repositories {
jcenter()
}
dependencies {
//视图绑定 butterknife
compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
}
在activity中:
onCreate里面添加:
ButterKnife.bind(this);
使用:
@BindView(R.id.btn_one)
Button btnOne;
@OnClick(R.id.btn_one)
public void goOne(){
Toast.makeText(MainActivity.this,"sa",Toast.LENGTH_SHORT).show();
}