1.Download the latest JAR or grab via Maven
2.Gradle
compile 'com.jakewharton:butterknife:7.0.1'
Example
class ExampleActivity extends Activity { @Bind(R.id.user) EditText username; @Bind(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... } }
-----------------------------------------------
ButterKnife後,
讓Annotation單獨一行顯示,
不必再切成兩行,設定:
File > Settings > Editor > Code Style > Java > Filed annotations > Do not wrap after single annotation 打勾。
沒有留言:
張貼留言