butterknife 中的“@Bind”和“@BindView”有什么区别?
What is the difference between `@Bind` and `@BindView` in butterknife?
我刚开始使用 butterknife。
在项目中,同事使用了butterknife,版本是7.0.0。
我看到他写@Bind(R.id.tv_name)
.
但是我看butterknife官网butterknife版本是8.0.1,语法是@BindView(R.id.tv_name)
语法有变化吗?或者两者都可以使用?还是别的?
它们之间有什么区别?
我在网上找不到答案
希望大家多多帮助,thx!
是的,语法在 8.0 版中发生了变化。
您可以在此处查看更改日志:https://github.com/JakeWharton/butterknife/blob/master/CHANGELOG.md#version-800-2016-04-25 以查看所有更改。但是从 7.X 到 8.X 的变更日志是:
@Bind
becomes @BindView
and @BindViews
(one view and multiple views, respectively).
- Calls to
bind
now return an Unbinder
instance which can be used to null
references. This replaces
the unbind
API and adds support for being able to clear listeners.
- New:
@BindArray
binds String
, CharSequence
, and int
arrays and TypeArray
to fields.
- New:
@BindBitmap
binds Bitmap
instances from resources to fields.
@BindDrawable
now supports a tint
field which accepts a theme attribute.
The runtime and compiler are now split into two artifacts.
compile 'com.jakewharton:butterknife:8.0.0'
apt 'com.jakewharton:butterknife-compiler:8.0.0'
New: apply
overloads which accept a single view and arrays of views.
- ProGuard rules now ship inside of the library and are included automatically.
@Optional
annotation is back to mark methods as being optional.
是的,这些关键字之间的唯一区别是 @Bind
在 v8.0.0 中重命名为 @BindView
。
请注意,ButterKnife.unbind()
已被删除,并替换为 bind()
返回的 Unbinder
,因此不会保留任何外部视图引用。
我刚开始使用 butterknife。
在项目中,同事使用了butterknife,版本是7.0.0。
我看到他写@Bind(R.id.tv_name)
.
但是我看butterknife官网butterknife版本是8.0.1,语法是@BindView(R.id.tv_name)
语法有变化吗?或者两者都可以使用?还是别的?
它们之间有什么区别?
我在网上找不到答案
希望大家多多帮助,thx!
是的,语法在 8.0 版中发生了变化。
您可以在此处查看更改日志:https://github.com/JakeWharton/butterknife/blob/master/CHANGELOG.md#version-800-2016-04-25 以查看所有更改。但是从 7.X 到 8.X 的变更日志是:
@Bind
becomes@BindView
and@BindViews
(one view and multiple views, respectively).- Calls to
bind
now return anUnbinder
instance which can be used tonull
references. This replaces theunbind
API and adds support for being able to clear listeners.- New:
@BindArray
bindsString
,CharSequence
, andint
arrays andTypeArray
to fields.- New:
@BindBitmap
bindsBitmap
instances from resources to fields.@BindDrawable
now supports atint
field which accepts a theme attribute.The runtime and compiler are now split into two artifacts.
compile 'com.jakewharton:butterknife:8.0.0'
apt 'com.jakewharton:butterknife-compiler:8.0.0'
New:
apply
overloads which accept a single view and arrays of views.- ProGuard rules now ship inside of the library and are included automatically.
@Optional
annotation is back to mark methods as being optional.
是的,这些关键字之间的唯一区别是 @Bind
在 v8.0.0 中重命名为 @BindView
。
请注意,ButterKnife.unbind()
已被删除,并替换为 bind()
返回的 Unbinder
,因此不会保留任何外部视图引用。