1》Android Studio Install ButterKnife Plugin
Similar to installing other plug-ins, as follows:
1.1》Open the Plugins interface
Follow the instructions in the figure above 1, 2, and 3 (note: I have installed this plugin in my Android Studio here, so the content displayed is not the same). Then restart Android Studio.
2》Use this open source project on the project (taking Android Studio as an example)
2.1》Add dependencies in bulk.gradle
Recompile the project and continue to operate after passing.
2.2》You can use annotations in the code
The example layout file of 2.2.1 is as follows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" 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=".MainActivity"> <TextView android:id="@+id/text_veiw_tv1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="TextView 1" /> <Button android:id="@+id/button_bt1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button1" /> <TextView android:id="@+id/text_veiw_tv2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="TextView 2" /> <Button android:id="@+id/button_bt2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button2" /> </LinearLayout>
2.2.2》Use annotations in the code
Select the above layout file name, right-click
After selecting "Confirm", the annotation form of each view with the id attribute in the layout file will be automatically generated.
As shown below:
@Bind(R.id.text_veiw_tv1) TextView textVeiwTv1; @Bind(R.id.text_veiw_tv2) TextView textVeiwTv2; @Bind(R.id.button_bt1) Button buttonBt1; @Bind(R.id.button_bt2) Button buttonBt2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); }The labels are as follows:
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.