你的位置:首页 > 软件开发 > 操作系统 > Butter Knife使用详解

Butter Knife使用详解

发布时间:2017-03-24 12:00:11
转载请注明出处:http://www.cnblogs.com/cnwutianhao/p/6610529.html Butter KnifeGithub地址: https://github.com/JakeWharton/butterknife官方说明给出的解释是 ...

Butter Knife使用详解

转载请注明出处:http://www.cnblogs.com/cnwutianhao/p/6610529.html 

 

Butter Knife

Github地址: https://github.com/JakeWharton/butterknife

Butter Knife使用详解

官方说明给出的解释是 Bind Android views and callbacks to fields and methods. 

Field and method binding for Android views which uses annotation processing to generate boilerplate code for you.

  • Eliminate findViewById calls by using @BindView on fields.
  • Group multiple views in a list or array. Operate on all of them at once with actions, setters, or properties.
  • Eliminate anonymous inner-classes for listeners by annotating methods with @OnClick and others.
  • Eliminate resource lookups by using resource annotations on fields.

意思就是:将Android视图和回调绑定到字段和方法。使用注释处理为您生成样板代码的Android视图的字段和方法绑定。通过在字段上使用@BindView消除findViewById调用。在列表或数组中分组多个视图。 使用操作,设置器或属性一次操作所有这些。通过使用@OnClick和其他方法注释方法,消除匿名内部类的侦听器。通过在字段上使用资源注释来消除资源查找。

 

官方文档给出了Butter Knife在Gradle里面如何配置

Butter Knife使用详解

 

下面我们就来配置Buffer Knife到工程里面

新建Android Studio工程(作者的Android Studio版本是2.3)

项目主体结构如下:

Butter Knife使用详解

首先,配置build.gradle(Project:XXX)

新建工程的build.gradle(Project:XXX)初始样子如下:

Butter Knife使用详解

然后我们按照官方文档进行配置

在repositories {}里面添加

mavenCentral()

原标题:Butter Knife使用详解

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录