android butterknife框架的简单使用

本文介绍了Android ButterKnife框架的使用,对比了其与xutils框架的效率优势,并提供了简单的入门步骤。首先,添加ButterKnife的依赖,然后在模块中应用。在实际配置过程中,可能会遇到Gradle下载问题,解决方案是取消“offline work”并清理项目。ButterKnife主要通过注解简化了findViewById和设置View监听的操作,如@BindView和@OnClick。除此之外,还有其他注解用于各种View的监听和资源绑定。
摘要由CSDN通过智能技术生成

记得很早之前有个xutils框架,就有这个功能,但是它是通过反射和代理发生在运行时期,所以效率肯定没butterknife框架效率高,今天就简单入门,如何使用:github:https://github.com/JakeWharton/butterknife


使用三方框架看下它提供的步骤就行,然后按照说的步骤一步步来一般就ok,

第一步:

dependencies {
  compile 'com.jakewharton:butterknife:8.8.1'
  annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}


添加这二个,这是目前最新的

第二步:

To use Butter Knife in a library, add the plugin to your buildscript:

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


看下我的配置:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

第三步:

and then apply it in your module:

<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值