Android Studio中ButterKnife插件的安裝與使用詳解
1》Android Studio 安裝ButterKnife插件
同安裝其他插件類似,如下:
1.1》打開Plugins界面
按照上圖中1,2,3指示操作(注意:這里我的Android Studio中已經(jīng)安裝了該插件,所以顯示的內(nèi)容不太一樣)。然后重啟Android Studio。
2》在項(xiàng)目上使用該開源項(xiàng)目(以Android Studio 為例)
2.1》在bulid.gradle中添加依賴
重新編譯一下該項(xiàng)目,通過后繼續(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”后,就會(huì)自動(dòng)生成各個(gè)在布局文件中帶有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); }
標(biāo)注如下:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android用注解與反射實(shí)現(xiàn)Butterknife功能
- Android中butterknife的使用與自動(dòng)化查找組件插件詳解
- 詳解Android Studio安裝ButterKnife插件(手動(dòng)安裝)
- 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依賴注入框架使用教程
相關(guān)文章
Java定義隊(duì)列結(jié)構(gòu),并實(shí)現(xiàn)入隊(duì)、出隊(duì)操作完整示例
這篇文章主要介紹了Java定義隊(duì)列結(jié)構(gòu),并實(shí)現(xiàn)入隊(duì)、出隊(duì)操作,結(jié)合完整實(shí)例形式分析了java數(shù)據(jù)結(jié)構(gòu)中隊(duì)列的定義、入隊(duì)、出隊(duì)、判斷隊(duì)列是否為空、打印隊(duì)列元素等相關(guān)操作技巧,需要的朋友可以參考下2020-02-02Servlet服務(wù)端實(shí)現(xiàn)原理詳解
Servlet是Sun公司開發(fā)動(dòng)態(tài)web的一門技術(shù),Sun公司在這些API中提供了一個(gè)接口叫做:Servlet,如果想開發(fā)一個(gè)Servlet程序,只需要完成兩個(gè)小步驟:編寫一個(gè)類,實(shí)現(xiàn)Servlet接口、把開發(fā)好的Java類部署到web服務(wù)器中。但是你了解Servlet實(shí)現(xiàn)的原理嗎2022-07-07詳解Spring與Mybatis整合方法(基于IDEA中的Maven整合)
這篇文章主要介紹了Spring與Mybatis整合方法(基于IDEA中的Maven整合),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10spring boot實(shí)現(xiàn)上傳圖片并在頁面上顯示及遇到的問題小結(jié)
最近在使用spring boot搭建網(wǎng)站的過程之中遇到了有點(diǎn)小問題,最終解決方案是在main目錄下新建了一個(gè)webapp文件夾,并且對(duì)其路徑進(jìn)行了配置,本文重點(diǎn)給大家介紹spring boot實(shí)現(xiàn)上傳圖片并在頁面上顯示功能,需要的朋友參考下吧2017-12-12Springboot Thymeleaf數(shù)字對(duì)象使用方法
這篇文章主要介紹了Springboot Thymeleaf數(shù)字對(duì)象使用方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2007-09-09Java創(chuàng)建線程池為什么一定要用ThreadPoolExecutor
本文介紹了Java創(chuàng)建線程池為什么一定要用ThreadPoolExecutor,手動(dòng)方式使用ThreadPoolExecutor創(chuàng)建線程池和使用Executors執(zhí)行器自動(dòng)創(chuàng)建線程池,下文更多相關(guān)內(nèi)容需要的小伙伴可以參考一下2022-05-05Java如何調(diào)用wsdl的webservice接口
這篇文章主要介紹了Java如何調(diào)用wsdl的webservice接口問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-05-05