您的位置:首页 > 移动开发 > Android开发

Android一键实例化控件及监听插件「ButterKnife」的简介及使用

2017-03-09 00:27 459 查看

概述

通过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





最终效果

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐