使用butterknife的原因是 当一个布局文件中组件太多的时候 就需要我们去写很多重复的代码 所以butterknife能够帮助我们减少一定的(无用的)代码量
1.android studio安装插件
首先点击File ->setting ->plugins
然后再新的对话框搜索butterknife 我这个是已经安装 点击install 会重启android Studio 然后就可以使用了
2.添加依赖
在build.gradle 添加依赖
compile 'com.jakewharton:butterknife:7.0.0'
3.使用
在需要写findViewById()这样的activity或者fragment中 对着R.layout.xxx右键 点击 generate 会有butterknife 点击 就出现了 然后修改自己想要的名称就行
相关链接:
butterknife Github地址 http://jakewharton.github.io/butterknife/