版权声明:本文为博主原创文章,未经博主允许不得转载。
Android jar 包
compile'com.jakewharton:butterknife:8.0.1'apt'com.jakewharton:butterknife-compiler:8.0.1'
代码
@BindView(R.id.tv_regist_trade)TextViewtv_regist_trade;@BindView(R.id.ll_trade_all)LinearLayoutllTrade;
ViewmContextView;
@Overrideprotected voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
mContextView= LayoutInflater.from(this).inflate(R.layout.activity_main,null);
setContentView(mContextView);
//初始化控件
ButterKnife.bind(this);
}
@Overrideprotected voidonDestroy() { //接触绑定ButterKnife.bind(this,mContextView).unbind();super.onDestroy();}
kotlinjar 包
compile'com.jakewharton:kotterknife:0.1.0-SNAPSHOT'
repositories {maven { url'https://oss.sonatype.org/content/repositories/snapshots/'}
}
代码
valtv_regist_trade: TextViewbybindView(R.id.tv_regist_trade)valllTrade: LinearLayoutbybindView(R.id.ll_trade_all)
/**当前Activity渲染的视图View**/varmContextView: View? =null
override funonCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)mContextView= LayoutInflater.from(this).inflate(R.layout.activity_main,null)super.setContentView(mContextView)
}