ButterKnife 8.4添加使用
来源:互联网 发布:淘宝订单好评短链接 编辑:程序博客网 时间:2024/04/30 22:41
ButterKnife是一个专注于Android系统的View注入框架,可以减少大量的findViewById以及 setOnClickListener代码,可视化一键生成
和其他依赖有些不一样,记录一下。
官网和github都有导入步骤。
官网:http://jakewharton.github.io/butterknife/
github:https://github.com/JakeWharton/butterknife
1、Library Dependency 搜索添加butterknife
或 compile 'com.jakewharton:butterknife:8.4.0'
2、 项目的Gradle文件
dependencies { classpath 'com.android.tools.build:gradle:2.1.2' 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、使用
public class MainActivity extends AppCompatActivity { @BindView(R.id.tv01) TextView tv01; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); tv01.setText("Hello,world!"); }}
注意:
- 需要在 setContentView() 或 inflate() 之后调用bind,申明的所有对象才会创建出来
- View变量声明的时候不能为private或者static.
- 除了Activity之外,你可以提供其他的View Root,来获取对象(执行注入).
详细使用方法:http://blog.csdn.net/skeeing/article/details/52386438
5、插件:Android Butterknife Zelezny
注意:需要在ID上右击或者alt+insert才能出来生成选项。其它地方无效
6、添加混淆
-keep class butterknife.** { *; } -dontwarn butterknife.internal.** -keep class **$$ViewBinder { *; } -keepclasseswithmembernames class * { @butterknife.* <fields>; } -keepclasseswithmembernames class * { @butterknife.* <methods>; }
2 0
- ButterKnife 8.4添加使用
- ButterKnife 8.4添加使用
- ButterKnife 添加使用
- Android之懒人框架 ButterKnife 8.4添加使用
- ButterKnife在8.4的使用
- ButterKnife:8.4.0的使用
- 【butterknife】butterknife:8.4.0 黄油刀使用详解。
- ButterKnife使用
- butterknife使用
- ButterKnife使用
- 使用butterknife
- ButterKnife使用
- butterknife使用
- ButterKnife使用
- butterknife使用
- ButterKnife使用
- ButterKnife使用
- ButterKnife使用
- CSS 相邻兄弟选择器
- JAVA静态代理与动态代理
- 一些容易混淆的属性
- 解析PayPal支付接口的PHP开发方式
- Activity一键退出的简单实现
- ButterKnife 8.4添加使用
- 欢迎使用CSDN-markdown编辑器
- Learnning Dlib(二) Create a DlibTest Project
- android:clipToPadding和android:clipChildren
- 工作随笔——贰(关于字符串非空判断与数据库中日期时间问题)
- Spring Boot下Druid连接池的使用配置分析
- 屏幕旋转
- 打造浪漫的Android表白程序
- 第一课(试听)