Butter Knife

将 Android 视图和回调绑定到字段和方法。「Bind Android views and callbacks to fields and methods.」

  • 所有者: JakeWharton/butterknife
  • 平台: Android, Linux, Mac, Windows
  • 许可证: Apache License 2.0
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Butter Knife

Attention: Development on this tool is winding down. Please consider switching to
view binding in the coming months.

Logo

Field and method binding for Android views which uses annotation processing to generate boilerplate
code for you.

  • Eliminate findViewById calls by using @BindView on fields.
  • Group multiple views in a list or array. Operate on all of them at once with actions,
    setters, or properties.
  • Eliminate anonymous inner-classes for listeners by annotating methods with @OnClick and others.
  • Eliminate resource lookups by using resource annotations on fields.
class ExampleActivity extends Activity {
  @BindView(R.id.user) EditText username;
  @BindView(R.id.pass) EditText password;

  @BindString(R.string.login_error) String loginErrorMessage;

  @OnClick(R.id.submit) void submit() {
    // TODO call server...
  }

  @Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple_activity);
    ButterKnife.bind(this);
    // TODO Use fields...
  }
}

For documentation and additional information see the website.

Remember: A butter knife is like a dagger, only infinitely less sharp.

Download

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

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

If you are using Kotlin, replace annotationProcessor with kapt.

Snapshots of the development version are available in Sonatype's snapshots repository.

Library projects

To use Butter Knife in a library, add the plugin to your buildscript:

buildscript {
  repositories {
    mavenCentral()
    google()
   }
  dependencies {
    classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.1'
  }
}

and then apply it in your module:

apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'

Now make sure you use R2 instead of R inside all Butter Knife annotations.

class ExampleActivity extends Activity {
  @BindView(R2.id.user) EditText username;
  @BindView(R2.id.pass) EditText password;
...
}

License

Copyright 2013 Jake Wharton

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

主要指标

概览
名称与所有者JakeWharton/butterknife
主编程语言Java
编程语言Shell (语言数: 5)
平台Android, Linux, Mac, Windows
许可证Apache License 2.0
所有者活动
创建于2013-03-05 08:18:59
推送于2023-09-02 07:41:30
最后一次提交2020-09-03 22:00:12
发布数48
最新版本名称10.2.3 (发布于 2020-08-12 13:58:29)
第一版名称butterknife-parent-1.0.0 (发布于 2013-03-05 00:56:09)
用户参与
星数25.5k
关注者数1k
派生数4.6k
提交数1k
已启用问题?
问题数1193
打开的问题数102
拉请求数346
打开的拉请求数17
关闭的拉请求数128
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?