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