插件介绍:ButterKnife是一个专注于Android系统的View注入框架,可以减少大量的findViewById以及setOnClickListener代码,可视化一键生成。又一神器,完美告别findViewById和setOnClickListener,由于是编译期生成代码的方式,对运行时没有任何副作用,只是编译期有一点点时间成本而已。
-------------------------------------------------------------下载插件-----------------------------------------------------------------
Android主面板--》File--》Settings--》Plugins--》Browse Repositories...--》查询框输入Android ButterKnife Zelezny查询--》点击Install下载
下载完毕提示重启AndroidStudio,确认重启即可
-------------------------------------------------------------下载插件-----------------------------------------------------------------
-------------------------------------------------------------配置插件依赖项-----------------------------------------------------------------
第二项配置:build.gradle(Module:app)配置为红色代码↓↓↓↓
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1" defaultConfig {
applicationId "com.example.ly.blogtestbutterknife"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
} dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.jakewharton:butterknife:8.4.0' apt 'com.jakewharton:butterknife-compiler:8.4.0'
}
第三项配置:build.gradle(Project)配置为红色代码↓↓↓↓
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// 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
} -------------------------------------------------------------使用插件-----------------------------------------------------------------