zoukankan      html  css  js  c++  java
  • ButterKnife使用

    这个快速注解插件非常好用,但是要注意,本人在用的时候用它去onclick的时候报空指针异常下面说说怎么用。

    1.在file里面选择

    搞定之后,还需要在APP下的build.gradle

    apply plugin: 'com.android.application'
    apply plugin: 'com.neenbedankt.android-apt' //加这一句
    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.2"
        defaultConfig {
            applicationId "com.example.administrator.myapplication0022"
            minSdkVersion 15
            targetSdkVersion 25
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support:appcompat-v7:25.2.0'
        testCompile 'junit:junit:4.12'
        compile 'com.jakewharton:butterknife:8.0.1'
        apt 'com.jakewharton:butterknife-compiler:8.0.1'//加这一句
     }

    ,另外在项目的build.gradle里面

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.2.0'
            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
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }

    这些都做完之后就可以快乐的使用注解和快速生成点击监听了,但有时候会generate会不出现butterknife这个插件选项,需要在File -> settings -> Plugins  -> Browse repositories -> 搜索ButterKnife,安装完成后restart,重启studio就可以用了

  • 相关阅读:
    Python-学习-小例子练习
    Python-学习-import语句导入模块
    Python-类-函数参数-takes 0 positional arguments but 1 was given
    虚拟现实-VR-UE4-构建光照显示光照构建失败,Swarm启动失败
    Qt 实现脉搏检测-2,简陋的功能产品
    Qt 蓝牙部分翻译
    Qt QLabel 播放GIF动画
    Qt 实现脉搏检测-1-心跳曲线部分
    C++学习014函数值传递和地址传递
    Ubuntu 普通用户无法启动Google chrome
  • 原文地址:https://www.cnblogs.com/laoyimou/p/6651885.html
Copyright © 2011-2022 走看看