Android Studio version 1.2.1
1. Add bold statement in Build.gradle, butterknife version is 6.1.0
Apply plugin:' Com.android.application 'Android {Compilesdkversion +Buildtoolsversion"21.1.2"Defaultconfig {ApplicationID"Com.example.wuqiong.demo"MinsdkversionTenTargetsdkversion +Versioncode1Versionname"1.0"} buildtypes {release {minifyenabledfalseProguardfiles Getdefaultproguardfile (' Proguard-android.txt '),' Proguard-rules.pro '}}}dependencies {Compile Filetree (dir:' Libs ', include: [' *.jar ']) Compile' com.android.support:appcompat-v7:22.1.1 '**compile' com.jakewharton:butterknife:6.1.0 '**}
2. Click the "Sync gradle File" button in the toolbar;
3. Modify the activity file, Butterknife.inject (this) the sentence must not be forgotten.
Public class mainactivity extends actionbaractivity { @InjectView(r.id.tv) TextView mTv;@InjectView(R.ID.BTN) Button mBtn;@OnClick(R.ID.BTN)voidDisplay () {Mtv.settext ("AAAA"); }@Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main); Butterknife.inject ( This); Mtv.settext ("BBBB"); }}
Butterknife app for MacBook under Android Studio