概述
- 通过java注解一键实例化控件及监听,大大减少反复findViewById()和setonclicktListener()的无脑工作量。
- 简化代码量,提高可读性,且对程序性能的影响微乎其微。
- 源码:https://github.com/JakeWharton/butterknife
使用
1. 安装插件,Settings --- Plugins --- Browse repositories --- 搜索Android ButterKnife Zelezny--- Install --- 重启AS
2. 在app的build.gradle中添加如下代码 --- Sync Now
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
compile 'com.jakewharton:butterknife:8.5.1'
apt 'com.jakewharton:butterknife-compiler:8.5.1'
}
3. 光标置于布局文件名上 --- Alt+Insert
最终效果