Android Studio中ButterKnife插件的安裝與使用詳解
1》Android Studio 安裝ButterKnife插件
同安裝其他插件類似,如下:
1.1》打開Plugins界面


按照上圖中1,2,3指示操作(注意:這里我的Android Studio中已經(jīng)安裝了該插件,所以顯示的內(nèi)容不太一樣)。然后重啟Android Studio。
2》在項目上使用該開源項目(以Android Studio 為例)
2.1》在bulid.gradle中添加依賴

重新編譯一下該項目,通過后繼續(xù)操作。
2.2》在代碼中就可以使用注解的方式了
2.2.1》示例布局文件如下:
<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》在代碼中使用注解
選擇上述布局文件名,右鍵



選擇“Confirm”后,就會自動生成各個在布局文件中帶有id 屬性的view的注解形式
如下所示:
@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);
}
標注如下:

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- Android用注解與反射實現(xiàn)Butterknife功能
- Android中butterknife的使用與自動化查找組件插件詳解
- 詳解Android Studio安裝ButterKnife插件(手動安裝)
- Android Studio使用ButterKnife和Zelezny的方法
- Android Kotlin環(huán)境使用ButterKnife的方法
- 解決Android Studio 3.0 butterknife:7.0.1配置的問題
- Android注解使用之ButterKnife 8.0詳解
- Android注解ButterKnife的基本使用
- Android?ButterKnife依賴注入框架使用教程
相關文章
教你用Springboot實現(xiàn)攔截器獲取header內(nèi)容
項目中遇到一個需求,對接上游系統(tǒng)是涉及到需要增加請求頭,請求頭的信息是動態(tài)獲取的,需要動態(tài)從下游拿到之后轉(zhuǎn)給上游,文中非常詳細的介紹了該需求的實現(xiàn),需要的朋友可以參考下2021-05-05
在Spring-Boot中如何使用@Value注解注入集合類
這篇文章主要介紹了在Spring-Boot中如何使用@Value注解注入集合類的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-08-08
Spring 定時任務@Scheduled 注解中的 Cron 表達式詳解
Cron 表達式是一種用于定義定時任務觸發(fā)時間的字符串表示形式,它由七個字段組成,分別表示秒、分鐘、小時、日期、月份、星期和年份,這篇文章主要介紹了Spring 定時任務@Scheduled 注解中的 Cron 表達式,需要的朋友可以參考下2023-07-07
Mybatis Plus條件構(gòu)造器ConditionConstructor用法實例解析
這篇文章主要介紹了Mybatis Plus條件構(gòu)造器ConditionConstructor用法實例解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-08-08
基于Java的度分秒坐標轉(zhuǎn)純經(jīng)緯度坐標的漂亮國基地信息管理的方法
本文以java語言為例,詳細介紹如何管理漂亮國的基地信息,為下一步全球的空間可視化打下堅實的基礎,首先介紹如何對數(shù)據(jù)進行去重處理,然后介紹在java當中如何進行度分秒位置的轉(zhuǎn)換,最后結(jié)合實現(xiàn)原型進行詳細的說明,感興趣的朋友跟隨小編一起看看吧2024-06-06

