欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

AndroidKotlin環(huán)境如何使用ButterKnife

這篇文章將為大家詳細講解有關(guān)Android Kotlin環(huán)境如何使用ButterKnife,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

松嶺網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,松嶺網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為松嶺上千多家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營銷網(wǎng)站建設(shè)要多少錢,請找那個售后服務(wù)好的松嶺做網(wǎng)站的公司定做!

先看看java環(huán)境的用法

1.安裝插件,然后重啟Android studio。

Android Kotlin環(huán)境如何使用ButterKnife

安裝插件.jpg

2.使用,點擊一下在setContentView(R.layout.activity_main);然后快捷鍵Alt+insert。

Android Kotlin環(huán)境如何使用ButterKnife

Alt+insert.jpg

3.使用。

Android Kotlin環(huán)境如何使用ButterKnife

使用.jpg

4.完成

@BindView(R.id.circleView)
CircleView circleView;
@BindView(R.id.tv_test)
TextView tvTest;
 
@Override
protected void onCreate(Bundle savedInstanceState)
{
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  ButterKnife.bind(this);
}
 
/*
* 多個控件點擊事件,會有大括號包起來,中間逗號隔開
* */
@OnClick({R.id.circleView, R.id.tv_test})
public void onViewClicked(View view)
{
  switch (view.getId())
  {
    case R.id.circleView:
      break;
    case R.id.tv_test:
      break;
  }
}
 
@Override
protected void onDestroy()
{
  ButterKnife.bind(this).unbind();
  super.onDestroy();
}

Kotlin環(huán)境

1.隨意新建一個kotlin文件

Android Kotlin環(huán)境如何使用ButterKnife

new kotlin.jpg

2.然后工程會有幾個地方變化

Android Kotlin環(huán)境如何使用ButterKnife

多了Configure.jpg

Android Kotlin環(huán)境如何使用ButterKnife

ok.jpg

Android Kotlin環(huán)境如何使用ButterKnife

module.jpg

Android Kotlin環(huán)境如何使用ButterKnife

project.jpg

3.添加對kotlin的支持

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
 
dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  implementation 'com.android.support:appcompat-v7:26.1.0'
  implementation 'com.android.support.constraint:constraint-layout:1.0.2'
  //控件插件
  implementation 'com.jakewharton:butterknife:8.8.1'
  kapt 'com.jakewharton:butterknife-compiler:8.8.1'
  compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}

Android Kotlin環(huán)境如何使用ButterKnife

添加kotlin支持.jpg

4.使用,直接用就好,不用再BindView了。

Android Kotlin環(huán)境如何使用ButterKnife

不需要BindView了.jpg

Android Kotlin環(huán)境如何使用ButterKnife

直接使用.jpg

5.注意要對應(yīng)的xml,以免同樣的控件id引起空指針異常。

Android Kotlin環(huán)境如何使用ButterKnife

關(guān)于“Android Kotlin環(huán)境如何使用ButterKnife”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

分享標(biāo)題:AndroidKotlin環(huán)境如何使用ButterKnife
本文鏈接:http://chinadenli.net/article14/giesge.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄動態(tài)網(wǎng)站品牌網(wǎng)站設(shè)計微信公眾號電子商務(wù)虛擬主機

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計