ButterKnife & Zelezny插件基本使用

来源:互联网 发布:recyclerview优化 编辑:程序博客网 时间:2024/06/07 11:28

GitHub地址

配置

  • Project build.gradle
buildscript {    repositories {        jcenter()    }    dependencies {        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'    }}
  • Module build.gradle
apply plugin: 'android-apt'
dependencies {    compile 'com.jakewharton:butterknife:8.4.0'    apt 'com.jakewharton:butterknife-compiler:8.4.0'}

基本用法

  • findViewById
    @BindView(R.id.tv_hello)    TextView mTvHello;
  • Bind
    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(getContentView());        ButterKnife.bind(this); //要在setContentView后调用    }
  • setOnClickListener
    @OnClick(R.id.tv_hello)    public void onClick(){        Toast.makeText(this, "hello ---- 1", Toast.LENGTH_SHORT).show();    }

Zelezny插件的使用

  1. Settings -> Plugins
  2. 搜索Zelezny
  3. Click Browse to search for non-bundled plugins
  4. Install -> Restart
  5. 右键layout使用
0 0
原创粉丝点击