ButterKnife使用

1、BuildScripts,添加红色部分

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'org.greenrobot:greendao-gradle-plugin:3.2.2'
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

2、app BuildGradle中添加红色部分

apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'
apply plugin: 'com.jakewharton.butterknife'
dependencies {
    implementation 'com.android.support:support-v4:26.1.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
    compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
    compile 'org.greenrobot:greendao:3.2.2'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.google.zxing:core:3.3.0'
    compile 'com.android.support:appcompat-v7:26+'
    compile 'com.android.support:recyclerview-v7:26+'
    compile project(path: ':library')
    compile project(path: ':orbbec')
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    compile 'com.jakewharton:butterknife:8.4.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}

3、Activity中测试

@BindView(R2.id.test) Button btnTest;//使用ButterKnife方法绑定按钮

onCreate中

ButterKnife.bind(this);
 

其他可以和传统按钮一样的方法使用,或者注解方式使用。

posted @ 2018-10-12 11:02  zhaogaojian  阅读(367)  评论(0编辑  收藏  举报