Android开发之注解式框架ButterKnife的使用
其实ButterKnife的注解式,与xUtils的ViewUtils模块基本上差不多,只要用过xUtils,这个框架基本上就会了。
一、原理。
最近发现一个很好用的开源框架,蛮不错的,可以简化你的代码,是关于注解的。不多说直接进入使用步骤讲解。
二、步骤。
1、准备阶段,先到官网( http://jakewharton.github.io/butterknife/ )上jar包,下载下来。
2、把下载下来的jar包,放到项目的libs下,就会自动导入项目了。
3、配置eclips,鼠标对准需要注解的项目,单击右键 poperties –>java Compiler –>
Annotation Procession –> 钩一下 Enable project specific settings 其它的就会自动钩上了
–> Factory Path ( 钩一下Enable project specific settings )–> 最后Add …. JARs 把刚刚下载的jar包来。这样eclips配置就可以了。
4、以下是图片讲解。




5、是用注解,直接上代码。
xml部分
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/tv_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world"
tools:context=".MainActivity" />
</RelativeLayout>
java部分
package com.msquirrel.main;
import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView; public class MainActivity extends Activity { @InjectView(R.id.tv_test)
TextView tvTest; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.inject(this);
tvTest.setText("test");
} @OnClick(R.id.tv_test)
public void sayHi() {
tvTest.setText("Hello!");
}
}
这样就算完成了,就可以使用注解了。
Android开发之注解式框架ButterKnife的使用的更多相关文章
- Android开发之注解式框架ButterKnife在ADT中的设置
使用注解式框架ButterKnife的时候,导入到ADT中,结果项目中注解的view无效,如点击button等无任何的反应. 然后在ButterKnife的官网查看到解决办法:http://jakew ...
- Android开发中用到的框架、库介绍
Android开发中用到的框架介绍,主要记录一些比较生僻的不常用的框架,不断更新中...... 网路资源:http://www.kuqin.com/shuoit/20140907/341967.htm ...
- Web移动前端开发-——bootstarp响应式框架
移动端WEB开发之响应式布局 1.0 响应式开发原理 1.1 响应式开发原理 就是使用媒体查询针对不同宽度的设备进行布局和样式的设置,从而适配不同设备的目的. 设备的划分情况: 小于768的为超小屏幕 ...
- Android 编译时注解解析框架
2.注解 说道注解,竟然还有各种分类,得,这记不住,我们从注解的作用来反推其分类,帮助大家记忆,然后举例强化大家的记忆,话说注解的作用: 1.标记一些信息,这么说可能太抽象,那么我说,你见过@Over ...
- Android开发之隐式Intent中Intent-filter的三个属性-action,category,data
使用隐式Intent时,需要使用到意图过滤器Intent-filter.Intent-filter含有三个属性:action,category,data.通过这三个属性的组合,可以启动想要启动的act ...
- Android开发:显式/隐式Intent
显式跳转 是在已知包名和类名的情况下常用的跳转方法: Intent mIntent = new Intent(); mIntent.setClassName("com.android.set ...
- android开发学习--网络请求框架RxJava+Retrofit
看了好多的博客,终于弄清楚了Rxjava和Retrofit,给大家推荐几个不错的文章: https://gank.io/post/56e80c2c677659311bed9841 这个文章是只用Ret ...
- Android开发 内存泄露检测框架LeakCanary
前言 挖坑后续填坑 中文网站:https://www.liaohuqiu.net/cn/posts/leak-canary-read-me/ gitbub:https://github.com/squ ...
- 03springMVC注解式控制器开发
注解式控制器开发简介 注解式控制器开发HelloWorld HelloWorld的运行流程 处理器定义 REST简介 URL路径映射 数据绑定 不同的Model有相同的属性的处理 静态资源的处理 1 ...
随机推荐
- C# - write values to configuration file
using System.Configuration;System.Configuration.Configuration config = ConfigurationManager.OpenExeC ...
- python3 pyqt5 和eric5配置教程
一.大纲内容: 1.预备PC环境: 2.预备安装程序: 2.1.下载Python3.2 2.2.下载PyQt4 2.3.下载Eric5 3.安装配置步骤: 3.1.安装Pyhon3.2 3.2.安装P ...
- C# Winform程序请求管理员权限
如果你的Winform程序需要管理员权限才能正常执行,请加入如下代码: static class Program { /// <summary> /// 应用程序的主入口点. /// &l ...
- (转)C#与Android通过adb实现usb通讯
转自:http://blog.csdn.net/linweidong/article/details/6273507 需求: Android的apk获取手机信息,把结果发给PC client 注意地方 ...
- 1006. Sign In and Sign Out
#include <stdio.h> #include <algorithm> #include <iostream> #include <string.h& ...
- UITableView实现格瓦拉飞天投票模块-b
格瓦拉目前来说动画效果确实做的还比较好,虽然不是说很炫但做到精致,这次就模仿了它投票的模块.其实想到要实现它还是有很多方法,不过这次我还是采用了苹果自带控件UITableView简简单单来实现它,再次 ...
- poj 1659 Frogs' Neighborhood (DFS)
http://poj.org/problem?id=1659 Frogs' Neighborhood Time Limit: 5000MS Memory Limit: 10000K Total S ...
- Linux学习笔记(6)-工作管理
什么是工作管理 工作来自job命令的翻译,job命令可以查看后台工作的进程.举例来说什么是工作管理,当你要打包一个比较大的目录时,很耗时间,但是你同时又需要使用别的命令.你会想我可以到开几个终端进行登 ...
- C# DataTable
http://www.cnblogs.com/xun126/archive/2010/12/30/1921557.html http://msdn.microsoft.com/zh-cn/librar ...
- mybatis include标签
使用mybatis 的include标签达到SQL片段达到代码复用的目的 示例: xml文件 <sql id="paysql"> payid,p.oid,p.bdate ...