ButterKnife 8.4添加使用
2016-08-31 13:23
316 查看
ButterKnife是一个专注于Android系统的View注入框架,可以减少大量的findViewById以及 setOnClickListener代码,可视化一键生成
和其他依赖有些不一样,记录一下。
官网和github都有导入步骤。
官网:http://jakewharton.github.io/butterknife/
github:https://github.com/JakeWharton/butterknife
1、Library Dependency 搜索添加butterknife
或
2、 项目的Gradle文件
3、 app的Gradle文件
4、使用
注意:
需要在 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、添加混淆
和其他依赖有些不一样,记录一下。
官网和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>; }
相关文章推荐
- Android之懒人框架 ButterKnife 8.4添加使用
- ButterKnife 8.4添加使用
- android butterknife8.4配置使用时的问题
- ButterKnife 8.4 安装使用
- 关于androidStudio中使用ButterKnife8.4.0时点击事件显示为未使用
- BufferKnife8.8.1和Android ButterKnife Zelezny的添加与使用
- ButterKnife 8.4 注解框架的使用
- AS2.2使用Butterknife8.4(8.x)遇到的坑。
- ButterKnife 添加使用
- 使用ButterKnife8.4报空指针异常
- 最新版本ButterKnife8.4的使用
- ButterKnife8.4使用配置
- Android开发之注解式框架ButterKnife的使用
- Android ButterKnife注入框架 使用
- 在Eclipse或者ADT中使用ButterKnifeZelezny,Android组件初始化从此变得简单易懂!!!!
- Android Butterknife框架基本使用教程
- Android Studio上方便使用butterknife注解框架的偷懒插件Android Butterknife Zelezny
- butterknife7.0的使用
- 在Eclipse或者ADT中使用ButterKnifeZelezny,Android组件初始化从此变得简单易懂!!!!,androideclipseadt
- 简单的butterknife使用方法