《Android進階之光》--ButterKnife

來源:互聯網
上載者:User

標籤:script   process   tor   editable   boolean   const   pil   java   list   

No1:

添加依賴庫

Project的build.gradle檔案添加

buildscript{    ...    dependencies{    ...    classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8‘    }}

在Module:app的build.gradle檔案添加

apply plugin:‘com.neenbedankt.android-apt‘...dependencies{...compile ‘com.jakewharton:butterknife:8.4.0‘apt ‘com.jakewharton:butterknife-compiler:8.4.0‘}

No2:

繫結控制項id

@BindView(R.id.tv_text)TextView tv_text;

No3:

綁定資源

@BindString(R.string.app_name)String appName;@BindArray(R.array.swordsman)String[] swordsman;@BindDimen(R.dimen.activity_horizontal_margin)float margin;

No4:

綁定監聽

@OnClick(R.id.bt_button1)public void showToast(){}@OnLongClick(R.id.bt_button2)public boolean setText(Button button){    return true;}
@OnTextChanged(value=R.id.et_edittext,callback=OnTextChanged.Callback.BEFORE_TEXT_CHANGED)void beforeTextChanged(CharSequence s,int start,int count,int after){}@OnTextChanged(value=R.id.et_edittext,callback=OnTextChanged.Callback.TEXT_CHANGED)void onTextChanged(CharSequence s,int start,int before,int count){}@OnTextChanged(value=R.id.et_edittext,callback=OnTextChanged.Callback.AFTER_TEXT_CHANGED)void afterTextChanged(Editable s){}
@OnTouch(R.id.bt_button3)public boolean onTouch(View view,MotionEvent event){    return true;}@OnItemClick(R.id.lv_list)void onItemClick(int position){}

No5:

可選綁定

@Nullable@BindView(R.id.tv_toptext)TextView name;

No6:

ButterKnife註解處理器是ButterKnifeProcessor,主要處理邏輯都在process方法中

->findAndParseTargets

->brewJava

->createBinding

->findBindingConstructorForClass

->findRequiredViewAsType

->findRequiredView

->DecorView.findViewById

->castView

《Android進階之光》--ButterKnife

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.