我就随便玩玩

准备在这里记录一些事情

导航

android 第三方开源库 学习汇总之Butter Knife

如果直接在App中使用,那么只需要在app的build.gradle中添加即可。

android {
  ...
  // Butterknife requires Java 8.
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

dependencies {
  implementation 'com.jakewharton:butterknife:10.2.0'
  annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'
}

使用时,请在目标activity上调用 ButterKnife.bind(this); 用来绑定ButterKnife和Activity

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
    }

 

 

 

具体使用:

绑定按钮

    @OnClick(R.id.btn_butterknife)
    public void onClicked(View view)
    {
        switch (view.getId())
        {
            case  R.id.btn_butterknife:
                Log.d("Demo", "" +  R.id.btn_butterknife);
                break;
        }
    }

绑定文本输入框

    @BindView(R.id.tv_butterknife)
    TextView tv_butterknife;
tv_butterknife.setText("demo123");

 

posted on 2019-11-11 15:15  我就随便玩玩也要起名  阅读(235)  评论(0编辑  收藏  举报