一,配置butterknife

Configure your project-level build.gradle to include the 'android-apt' plugin:

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
Then, apply the 'android-apt' plugin in your module-level build.gradle and add the Butter Knife dependencies: apply plugin: 'android-apt' android {
...
} dependencies {
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
}
二,安装ButterKnifeZelezny插件
       
File -> Seting -> Plugins -> Browser Responsities ->Butterknife Zelezny
 
三,使用插件时xml中的布局写法
/**
* 首页选择
*/
public class MainListActivity extends AppCompatActivity { @BindView(R.id.marquee_tv)
TextView mMarqueeTv;
@BindView(R.id.more_tv)
TextView mMoreTv; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_list);
ButterKnife.bind(this);
} @OnClick({R.id.marquee_tv, R.id.more_tv})
public void onClick(View view) {
switch (view.getId()) {
case R.id.marquee_tv:
break;
case R.id.more_tv:
break;
}
}
}

  

像做到如上效果还需两步:
step 1> 设置ButterKnife Zelezny
 
 
step 2> xml布局变量写法 
 
activity_main_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
>
<TextView
android:id="@+id/marquee_tv"
style="@style/item_main_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Marquee demo"
/>
<TextView
android:id="@+id/more_tv"
style="@style/item_main_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="More demo"
/>
</LinearLayout>

  

 
现在请在Activity的布局文件名字上面右键Generate->Generate ButterKnife Injection 
Enjoys!

最新文章

  1. jQuery 实时监听&lt;input&gt;输入值的变化
  2. CSS3让一段文字多余的用省略号表示,当鼠标移动上去的时候显示全部文字
  3. Centos7.X 源码编译安装subversion svn1.8.x
  4. 图片标签img中,为什么使用alt属性没用
  5. [原创]Android系统中常用JAVA类源码浅析之HashMap
  6. Apache 学习笔记(心得)
  7. hive与hbase的区别与联系
  8. ThreadLocal实现方式&amp;使用介绍---无锁化线程封闭
  9. 【转】linux(Ubuntu)配置svn仓库,搭建svn服务器
  10. poj 1743 男人八题之后缀数组求最长不可重叠最长重复子串
  11. Swift 3.0项目迁移的一些记录
  12. 解决git Failed to connect to 127.0.0.1 port xxxx: Connection refused
  13. 《Java》第五周学习总结20175301
  14. GDAL create kml
  15. UOJ#219/BZOJ4650 [NOI2016]优秀的拆分 字符串 SA ST表
  16. 【刷题】LOJ 2863 「IOI2018」组合动作
  17. myeclipse和maven的clean和build
  18. USB线插拔检测使用UEventObserver检测uevent事件的分析
  19. Egit的merge合并冲突具体解决方法
  20. bzoj 5341: [Ctsc2018]暴力写挂

热门文章

  1. BZOJ1564 NOI2009二叉查找树(区间dp)
  2. 洛谷 P3376 【模板】网络最大流
  3. poj 3254 状态压缩
  4. HDU 4352 数位dp
  5. golang channel状态表
  6. 使用Eclipse进行SWT编程
  7. springboot创建maven多模块项目
  8. @PathParam 和 @QueryParam
  9. CF821 B. Okabe and Banana Trees 简单数学
  10. JVM调优总结:一些概念