最新版本ButterKnife8.4的使用

来源:互联网 发布:韩国古代历史 知乎 编辑:程序博客网 时间:2024/05/21 03:58

1、Library Dependency 搜索添加butterknife 
或  compile 'com.jakewharton:butterknife:8.4.0' 
2、 项目的Gradle文件

dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
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
}

3、 app的Gradle文件

``` apply plugin: 'com.neenbedankt.android-apt'//增加这一句dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    testCompile 'junit:junit:4.12'    compile 'com.android.support:appcompat-v7:24.0.0'    compile 'com.jakewharton:butterknife:8.4.0'//buttetknife    apt 'com.jakewharton:butterknife-compiler:8.4.0'//添加这一句 } ```

4、使用

  • 需要在 setContentView() 或 inflate() 之后调用bind,申明的所有对象才会创建出来
  • View变量声明的时候不能为private或者static.
  • 除了Activity之外,你可以提供其他的View Root,来获取对象(执行注入).

详细使用方法:http://blog.csdn.net/skeeing/article/details/52386438

5、添加混淆

#ButterKnife
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}
-dontwarn butterknife.Views$InjectViewProcessor
-dontwarn com.gc.materialdesign.views.**

 

0 0
原创粉丝点击