android studio 版本1.2.1
1. 在build.gradle中增加加粗的语句,butterknife的版本为6.1.0
apply plugin: ‘com.android.application‘
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.wuqiong.demo"
minSdkVersion 10
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘
}
}
}
dependencies {
compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])
compile ‘com.android.support:appcompat-v7:22.1.1‘
**compile ‘com.jakewharton:butterknife:6.1.0‘**
}
2.点击工具栏中的“同步gradle文件“按钮;
3.修改activity文件, ButterKnife.inject(this)这一句一定不要忘了。
public class MainActivity extends ActionBarActivity {
@InjectView(R.id.tv)
TextView mTv;
@InjectView(R.id.btn)
Button mBtn;
@OnClick(R.id.btn)
void display() {
mTv.setText("aaaa");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.inject(this);
mTv.setText("bbbb");
}
}
Macbook下Android studio的butterknife的应用
原文地址:http://blog.csdn.net/wuqiong657/article/details/46508599