Butter Knife(牛油刀)

官网(Butter Knife(牛油刀))

github

  1. 添加依赖

    apply plugin: ‘com.jakewharton.butterknife’
    android {

    // Butterknife requires Java 8.
    compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    }
    }
    dependencies {
    implementation ‘com.jakewharton:butterknife:10.2.1’
    annotationProcessor ‘com.jakewharton:butterknife-compiler:10.2.1’
    }

    Library projects

    buildscript {
    repositories {
    mavenCentral()
    google()
    }
    dependencies {
    classpath ‘com.jakewharton:butterknife-gradle-plugin:10.2.1’
    }
    }

  2. 安装 插件
    打开file—》setting–》plugins–》Marketplace–搜索Butterknife

  3. 使用
    在BaseActivity的 onCreate 中初始化

 @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        bind = ButterKnife.bind(this);

    }
在onDestroy中解绑
 @Override
    protected void onDestroy() {
        super.onDestroy();
        bind.unbind();
    }

你可能感兴趣的:(第三方框架)