控件注解butterknife:8.4.0的使用

本文介绍如何在Android项目中使用Butterknife进行视图绑定,包括在build.grade文件中配置依赖,以及在Activity中使用注解实现视图绑定。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在项目的build.grade文件中:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        //这里配置 apt 供butterknife使用
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

在app的build.grade文件中:

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android{...}

repositories {
    jcenter()
}


dependencies {
    //视图绑定 butterknife
    compile 'com.jakewharton:butterknife:8.4.0'
    apt 'com.jakewharton:butterknife-compiler:8.4.0'
}

在activity中:

onCreate里面添加:
ButterKnife.bind(this);

使用:
@BindView(R.id.btn_one)
    Button btnOne;
@OnClick(R.id.btn_one)
    public void goOne(){
        Toast.makeText(MainActivity.this,"sa",Toast.LENGTH_SHORT).show();
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值