Android: Kotlin with Butterknife

前端 未结 10 995
鱼传尺愫
鱼传尺愫 2020-12-24 04:55

I\'m trying to use Kotlin with Butterknife for my Android Application.

Here is my build.gradle

dependencies {
    ...
    compile \'com.jakewharton:b         


        
10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-24 05:48

    In Kotlin, actually there is no need (or) necessity for going ButterKnife concepts. because in your activity you can directly refer the view _id of the layout file as referred below.

    layout.xml

    Activity.kt

     btn_prestage.setBackgroundResource(R.drawable.staging_on)
     btn_prestage.setOnClickListener{ view ->
                Snackbar.make(view, "My Action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show() }
    

    build.gradle(app)

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-android-extensions'
    apply plugin: 'kotlin-kapt'
    
    android {
       dependencies {... }
    }
    
    kapt {
        generateStubs = true
    }
    

提交回复
热议问题