国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > Java > 正文

Android Studio中ButterKnife插件的安裝與使用詳解

2024-07-13 10:15:52
字體:
供稿:網(wǎng)友

1》Android Studio 安裝ButterKnife插件

同安裝其他插件類似,如下:

1.1》打開Plugins界面

Android,Studio,ButterKnife

Android,Studio,ButterKnife

按照上圖中1,2,3指示操作(注意:這里我的Android Studio中已經(jīng)安裝了該插件,所以顯示的內(nèi)容不太一樣)。然后重啟Android Studio。

2》在項(xiàng)目上使用該開源項(xiàng)目(以Android Studio 為例)

2.1》在bulid.gradle中添加依賴

Android,Studio,ButterKnife

重新編譯一下該項(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》在代碼中使用注解

選擇上述布局文件名,右鍵

Android,Studio,ButterKnife

Android,Studio,ButterKnife

Android,Studio,ButterKnife

選擇“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)注如下:

Android,Studio,ButterKnife

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VeVb武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請移步到JAVA教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 哈巴河县| 深泽县| 临潭县| 甘孜县| 家居| 湛江市| 历史| 双桥区| 项城市| 平舆县| 惠安县| 大姚县| 四会市| 昌邑市| 惠来县| 锦州市| 哈密市| 承德市| 红桥区| 荔浦县| 吴堡县| 拜泉县| 葵青区| 伊川县| 桦甸市| 四会市| 遂溪县| 南丰县| 沙洋县| 宁强县| 屯门区| 东兰县| 专栏| 托克逊县| 孟津县| 金昌市| 法库县| 邓州市| 蒙山县| 亳州市| 锡林郭勒盟|