flu*_*ter 3 java android annotations android-studio butterknife
刚刚遇到了奶油刀.我在gradle(module:app)文件中添加了这行:compile'com.jakewharton:butterknife:7.0.1'
它同步没有任何错误.我可以将'butterknife.Butterknife'导入到我的类文件中,其中导入usualyy.但是无法导入butterknife.InjectView似乎没有?有什么建议?
Butterknife 7.0.0版本包括重命名注释动词的重大变化.这在更改日志中突出显示并反映在网站中.
Version 7.0.0 *(2015-06-27)*
----------------------------
* `@Bind` replaces `@InjectView` and `@InjectViews`.
* `ButterKnife.bind` and `ButterKnife.unbind` replaces `ButterKnife.inject`
and `ButterKnife.reset`, respectively.
...
Run Code Online (Sandbox Code Playgroud)
http://jakewharton.github.io/butterknife/是一本非常好的,最新的用法介绍.
这是最简单的用法:
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...
}
}
Run Code Online (Sandbox Code Playgroud)
@InjectView不再可用,并由代替@BindView。我们将必须导入Butterknife依赖项才能使用注释。有关黄油刀的更多信息,请点击此处:-http : //jakewharton.github.io/butterknife/
@BindView 注释可以实现为:
@BindView(R.id.button_id)
Run Code Online (Sandbox Code Playgroud)
请注意,您将需要ButterKnife.bind(this);从onCreate()main活动的方法调用来启用Butterknife批注。关于此实现的示例可能类似于:
public class MainActivity extends AppCompatibilityActivity{
@BindView(R.id.editText_main_firstName)
EditText firstName;
@BindView(R.id.editText_main_lastName)
EditText lastName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Needs to be called to enable Butterknife annotations
ButterKnife.bind(this);
}
}
Run Code Online (Sandbox Code Playgroud)
如果您正在使用Butterknife片段,则使用Butterknife.bind(this,view)该视图作为片段视图,即:-
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_other_product_category, container, false);
ButterKnife.bind(this, view);
return view;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5763 次 |
| 最近记录: |