您好,欢迎访问四川鑫光豪耀机电有限公司!

咨询热线:

18980820575
✕

营山发电机维修,营山柴油发电机维修,品牌发电机维修,发电机维修服务公司

AndroidStudio中ButterKnife插件的安装与使用详解-创新互联

1》Android Studio 安装ButterKnife插件

创新互联建站客户idc服务中心,提供中国电信云锦天府、成都服务器、成都主机托管、成都双线服务器等业务的一站式服务。通过各地的服务中心,我们向成都用户提供优质廉价的产品以及开放、透明、稳定、高性价比的服务,资深网络工程师在机房提供7*24小时标准级技术保障。

同安装其他插件类似,如下:

1.1》打开Plugins界面



按照上图中1,2,3指示操作(注意:这里我的Android Studio中已经安装了该插件,所以显示的内容不太一样)。然后重启Android Studio。

2》在项目上使用该开源项目(以Android Studio 为例)

2.1》在bulid.gradle中添加依赖


重新编译一下该项目,通过后继续操作。

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> 
友情链接 :