项目github地址:
https://github.com/JakeWharton/butterknife
3,搜索ButterKnife,这里最新版本是8.5.1
配置插件
1,dependencies {
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}
使用
看了网上的教程都需要配置这个,GitHub上的教程没配置,没有apt,onClick绑定不了监听,而配置apt有时候又会出现问题,所以使用annotationProcessor来解决这个问题。
1,

3,搜索ButterKnife,这里最新版本是8.5.1
配置插件
1,dependencies {
compile 'com.jakewharton:butterknife:8.5.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}
使用
1,
class ExampleActivity extends Activity {
@BindView(R.id.user) EditText username;
@BindView(R.id.pass) EditText password;
@BindString(R.string.login_error) String loginErrorMessage;
@OnClick(R.id.submit) void submit() {
// TODO call server...
}
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_activity);
ButterKnife.bind(this);
// TODO Use fields...
}
}
更多用法介绍 http://jakewharton.github.io/butterknife/
本文介绍了ButterKnife的配置及使用方法,包括如何通过annotationProcessor实现视图绑定和事件监听,提供了具体代码示例。
479

被折叠的 条评论
为什么被折叠?



