ButterKnife在GitHub的地址:https://github.com/JakeWharton/butterknife

最新的版本是:8.4.0

app 模块的build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.example.liberty.hteach"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
} dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.0.0'
// compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
compile 'com.android.support:design:24.0.0'
compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-annotations:24.0.0'
}

项目build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
// jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0-rc2'
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
}

MainActivity:

public class MainActivity extends AppCompatActivity {

//    private TabLayout tabLayout;
// private ViewPager viewPager; @BindView(R.id.viewPager)
ViewPager viewPager;
@BindView(R.id.tabs)
TabLayout tabLayout;
@BindArray(R.array.titles)
String []titles; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// viewPager= (ViewPager) findViewById(R.id.viewPager);
// tabLayout= (TabLayout) findViewById(R.id.tabs);
ButterKnife.bind(this);
}
}

在新的8.4版本中去除了unbind方法

Unbinder mUnbinder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_activity);
mUnbinder=ButterKnife.bind(this); //保存引用

@Override
protected void onDestroy() {
super.onDestroy();
mUnbinder.unbind(); //释放所有绑定的view
}

Android ButterKnife配置使用的更多相关文章

  1. Android Butterknife框架

    Android Butterknife框架 注解攻略 时间 2014-02-27 09:28:09  Msquirrel原文  http://www.msquirrel.com/?p=95 一.原理. ...

  2. butterknife 配置了点击和绑定无效

    配置了butterknife 没有报错,但是控件绑定和点击均无效. 问题原因: butterknife配置不完善问题导致. 解决办法: 找到app的module的build.gradle depend ...

  3. 史上最简单的ButterKnife配置教程

    网上的教程感觉都是抄来抄去,没一个靠谱的 还是自己丰衣足食搞一个ButterKnife配置教程吧.. 我的Android Studio版本是3.3. 1.dependencies中添加依赖 imple ...

  4. 使用Android Butterknife

    我之前浏览过android butterknife 的使用 在android studio 中,很惊喜,已经成为一个插件来使用 这个android butterknife 最大的用处,就是直接生成la ...

  5. 手把手教android studio中安装Android Butterknife Zelezny (转)

    原文地址:http://blog.csdn.net/xin917480852/article/details/51176524 用来快速生成findViewById() 安装方法: 打开Android ...

  6. Win10下Android studio配置

    Win10下Android studio配置 一.安装Android Studio的准备工作 1.下载好JDK,去官网上找一个下载下来 2.安装JDK.并配置环境变量.安装过程:本人将使用的是jdk- ...

  7. [Android] 环境配置之正式版Android Studio 1.0

    昨天看见 Android Studio 1.0 正式版本发布了:心里挺高兴的. 算是忠实用户了吧,从去年开发者大会一开始出现 AS 后就开始使用了:也是从那时开始就基本没有用过 Eclipse 了:一 ...

  8. Android studio配置Git

    Android studio配置Git 1.下载window 版git并安装:下载地址 2.Android Studio设置git插件:File->Setting->Version Con ...

  9. [Android] 环境配置之基础开发环境(SDK/Android Studio)(转)

    [Android] 环境配置之基础开发环境(SDK/Android Studio)   博客: blog.csdn.net/qiujuer 网站: www.qiujuer.net 开源库: Geniu ...

随机推荐

  1. nw.js桌面软件开发系列 第0.1节 HTML5和桌面软件开发的碰撞

    第0.1节 HTML5和桌面软件开发的碰撞 当我们谈论桌面软件开发技术的时候,你会想到什么?如果不对技术本身进行更为深入的探讨,在我的世界里,有这么多技术概念可以被罗列出来(请原谅我本质上是一个Win ...

  2. IdentityServer4 使用OpenID Connect添加用户身份验证

    使用IdentityServer4 实现OpenID Connect服务端,添加用户身份验证.客户端调用,实现授权. IdentityServer4 目前已更新至1.0 版,在之前的文章中有所介绍.I ...

  3. iOS 后台处理

    iOS 后台处理的常见用途 1.进入后台时候删除资源:应用处于挂起状态的时候所占用的资源越少,该应用被iOS终止的风险就越低.通过从内存中清理那些易于重新创建的资源,可以增加应用驻留内存的机会,因此可 ...

  4. Android 添加ActionBar Buttons

    一.在res/menu文件夹下创建Xml文件 跟标签为menu,设置item <?xml version="1.0" encoding="utf-8"?& ...

  5. 检查sql执行效率

    SELECT  SUBSTRING(ST.text, ( QS.statement_start_offset / 2 ) + 1,                    ( ( CASE statem ...

  6. Android Bitmap 和 ByteArray的互相转换

    Android Bitmap 和 ByteArray的互相转换 移动平台图像处理,需要将图像传给native处理,如何传递?将bitmap转换成一个 byte[] 方便传递也方便cpp代码直接处理图像 ...

  7. 基于Node.js实现一个小小的爬虫

    以前一直听说有爬虫这种东西,稍微看了看资料,貌似不是太复杂. 正好了解过node.js,那就基于它来个简单的爬虫. 1.本次爬虫目标: 从拉钩招聘网站中找出“前端开发”这一类岗位的信息,并作相应页面分 ...

  8. Immutable(不可变)集合

    不可变集合,顾名思义就是说集合是不可被修改的.集合的数据项是在创建的时候提供,并且在整个生命周期中都不可改变. 为什么要用immutable对象?immutable对象有以下的优点: 对不可靠的客户代 ...

  9. Fedora 24中的日志管理

    Introduction Log files are files that contain messages about the system, including the kernel, servi ...

  10. 抛弃jQuery:DOM API之操作元素

    原文链接:http://blog.garstasio.com/you-dont-need-jquery/dom-manipulation/ 我的Blog:http://cabbit.me/you-do ...