MainActivity
package com.jj.yuekao.demo06;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.jj.yuekao.R;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
public class Main6Activity extends AppCompatActivity {
private Unbinder un;
@BindView(value = R.id.but_61)
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main6);
un= ButterKnife.bind(this);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(Main6Activity.this, "点击事件", Toast.LENGTH_SHORT).show();
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
un.unbind();
}
}
布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.jj.yuekao.demo06.Main6Activity">
<Button
android:id="@+id/but_61"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="按钮11111"
android:onClick="onClick"/>
</RelativeLayout>