ButterKnife 是这两年比较流行的开源库,是一个View注入框架,其主要功能是代替findViewByid()方法。同时还能够快速的添加监听事件,能够更容易的实现MVVM模式,是非常实用的工具之一。 刚开始使用ButterKnife的时候很多人可能会遇到NullPoi ...
ButterKnife 是这两年比较流行的开源库,是一个View注入框架,其主要功能是代替findViewByid()方法。同时还能够快速的添加监听事件,能够更容易的实现MVVM模式,是非常实用的工具之一。
刚开始使用ButterKnife的时候很多人可能会遇到NullPointerException或者“找不到符号”,这皆是由于ButterKnife配置有误。下面我们来详细的来说明ButterKnife的配置
首先我们需要导入ButterKnife
如图
也可以在这里添加
同时还需要安装ButterKnife的插件
这里我已经安装好了,看起来有一些不同。没安装的时候先搜索然后点下面的按钮就会出来了
然后配置
注意,这里如果没有完成上面安装插件的步骤会无法识别apt()
还不理解的话,下面就贴出完整的build.gradle吧
1 // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 3 buildscript { 4 repositories { 5 jcenter() 6 } 7 dependencies { 8 classpath 'com.android.tools.build:gradle:2.1.0' 9 classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'10 // NOTE: Do not place your application dependencies here; they belong11 // in the individual module build.gradle files12 }13 }14 15 allprojects {16 repositories {17 jcenter()18 }19 }20 21 task clean(type: Delete) {22 delete rootProject.buildDir23 }
原标题:Android studio ButterKnife8.1.0空指针/相关配置及其简单使用
关键词:Android
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。