ButterKnife初体验与认知JakeWharton

来源:互联网 发布:天猫淘宝京东的区别ppt 编辑:程序博客网 时间:2024/06/17 02:01

        ButterKnife是JakeWharton 大神编写的一个节省代码的框架。最直接的就是节约了 findViewById的重复编写工作,在控件定义之时就绑定了控件。

        项目的地址是在https://github.com/JakeWharton/butterknife 上面,使用方法如下:

        首先先在项目dependencies中下载(project)大神的第三方库 

dependencies {  compile 'com.jakewharton:butterknife:8.6.0'  annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'}
       compile是从网络上下载的lib库 annotationperocessor是谷歌专门用于注解的注解器

       然后在buildscript中调用:

buildscript {  repositories {    mavenCentral()   }  dependencies {    classpath 'com.jakewharton:butterknife-gradle-plugin:8.6.0'  }}

     mavenCentral指的是首先先在本地中查找是否有这个库,如果有优先使用本地的库,如果没有的话去网络中获取。(module)

     然后引入

    apply plugin: 'com.android.library'

    apply plugin: 'com.jakewharton.butterknife'

    代码运行,插件可能会不断的进行更新,最好是去github上面查看JakeWharton 大神最新的使用教程。还有很多种用法在更新跟增加

public class MainActivity extends Activity {    @BindView(R.id.tv_show) TextView tv_show;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        ButterKnife.bind(this);        Net();        tv_show.setText("成功了");    }}       

阅读全文
0 0
原创粉丝点击