当前位置: 移动技术网 > 移动技术>移动开发>Android > ButterKnife原理及其使用

ButterKnife原理及其使用

2020年08月11日  | 移动技术网移动技术  | 我要评论

ButterKnife原理及其使用

关于ButterKnife

ButterKnife是Jake Wharton开发的一款Android框架,用于Android系统的View注入框架,主要用于简化代码。减少在进行控件绑定以及控件事件编写时的重复编写,可用来取代findViewById以及setOnClickListener。

使用

在使用ButterKnife之前,需要先添加以下的依赖:

  1. 在Project的build.gradle中添加如下配置:
buildscript { repositories { google() jcenter() } dependencies { ... classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } 
  1. 在Module的build.gradle添加如下配置:
android { //... compileOptions { sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { //... implementation 'com.jakewharton:butterknife:10.2.2' annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.2' } 

以上所使用的ButterKnife是最新版本10.0.2,相关配置信息可到这里去查询:作者github

本文地址:https://blog.csdn.net/weixin_43781480/article/details/107922290

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网