好用的eclipse插件butterknife

来源:互联网 发布:淘宝丝袜女模特拍照 编辑:程序博客网 时间:2024/06/05 12:46
使用andorid studio开发的人肯定觉得butterknife很好用
jackwharton大神为我们提供了此开源框架

http://maven.outofmemory.cn/com.jakewharton/butterknife/

他可以帮助我们自动完成findviewbyid的操作
还可以帮助我们给对应的空间添加点击事件

1、使用之前首先需要进行Eclipse设置


http://jakewharton.github.io/butterknife/ide-eclipse.html


这里会出现一个问题,因为我们需要配置一下eclipse,但这个时候如果你是用的adt解压出来的eclipse,会发现Eclipse项目的Preference中,Java Compiler下没有Annotation Processing,那么怎么解决,请看下面这个博文:


http://blog.csdn.net/jerrywu145/article/details/51819140

2、基本操作


http://jakewharton.github.io/butterknife/index.html


@Bind(R.id.XXX)绑定id,等同于findViewById(R.id.xxx)

@BindColor(R.color.xxx)

@BindDrawable(R.drawable.xxx)

参考示例:

class ExampleActivity extends Activity {
@Bind(R.id.title) TextView title;
@Bind(R.id.subtitle) TextView subtitle;
@Bind(R.id.footer) TextView footer;

@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_activity);
ButterKnife.bind(this);
// TODO Use fields...
}
}

2 0
原创粉丝点击