Butterknife的使用
来源:互联网 发布:联影 算法怎么样 编辑:程序博客网 时间:2024/06/01 22:32
butterknife的使用
简介:ButterKnife是一个View注入框架,可以减少findViewById以及setOnClickListener代码。
github地址:https://github.com/JakeWharton/butterknife
一、添加依赖
1.1 主项目添加
在module的build.gredle 文件中的dependencies标签中添加
dependencies { compile 'com.jakewharton:butterknife:8.5.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'}
1.2 Library Module添加
如果Library Module也需要用到,则通过以下方式添加。
1.2.1 在Library Module的build.gredle 文件中的dependencies标签下添加
classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
1.2.2 在Library Module的build.gredle 文件中添加
apply plugin: 'com.android.library'apply plugin: 'com.jakewharton.butterknife'
二、如何使用
2.1 在Activity中使用
2.2 在Fragment中使用
2.3 view的绑定
2.3.1 单个View绑定 @BindView()
2.3.2 多个View绑定 @BindViews()
绑定Views
@BindViews({ R.id.button1, R.id.button2, R.id.button3 })public List<Button> buttonList ;
操作Views
buttonList.get( 0 ).setText( "hello 1 ");buttonList.get( 1 ).setText( "hello 2 ");buttonList.get( 2 ).setText( "hello 3 ");
2.3.3 绑定String @BindString()
2.3.4 绑定string里面array数组 @BindArray()
2.3.5 绑定Bitmap @BindBitmap()
2.3.6 绑定一个Color @BindColor()
可以绑定的类型:
注意:修饰类型不能是private 或者 static。否则会报错: @BindView fields must not be private or static.
2.3.7 绑定点击事件 @OnClick()
2.3.8 绑定长按事件 @OnLongClick()
可以绑定的类型:
三、在Android Studio上安装ButterKnife插件
3.1 打开Android Studio的Settins–>Pliugins,搜索Zelezny
3.2 安装插件
3.3 重启Android Studio
3.4 使用快捷方式
3.4.1 将光标放置到setContentView(R.layout.activity_login),右击选择Generate
3.4.2 选择Generate Butterknife injections
3.4.3 选择要绑定的控件,点击Comfirm
- butterknife的使用
- butterknife的使用
- ButterKnife的使用
- ButterKnife 的使用
- 兔子--ButterKnife的使用
- ButterKnife的使用
- ButterKnife的使用
- ButterKnife的简单使用
- ButterKnife的使用详解
- ButterKnife的简单使用
- ButterKnife的使用
- ButterKnife的使用
- ButterKnife的使用问题
- butterknife框架的使用
- Android Butterknife的使用
- ButterKnife的基本使用
- ButterKnife的使用步骤
- ButterKnife的使用
- 记录一次系统部分功能解耦重构
- Python学习笔记(四)—字典(dict)
- Java Interface用法
- Android应用设置多个启动图标,动态列换应用图标
- 获取泛型的Class类型
- Butterknife的使用
- 数值得整数次方--模拟pow函数的功能
- csapp 实验二 二进制炸弹
- 利用Android Studio的CMake来快速开发NDK
- multipart/form-data post 方法提交表单,后台获取不到数据
- C++ primer plus 阅读记录-使用类
- leetcode之单链表题目汇总
- bat脚本学习 --参数传递
- lua中table操作的相关函数