当前位置:   article > 正文

ButterKnife库(一个高效的工具库,小白只记录了一个用法-不深入研究,嘻嘻)

butterknife

ButterKnife库(一个高效的工具库)

作用是替代 findViewById()最基本的使用,它不会干扰软件运行效率,而且看着高效(通俗点:代码比较干净整洁)

今天新学了个工具库ButterKnife的基础用法

因为我用的是AndroidX,所以只记录AndroidX的配置

build.gradle添加依赖

    //butterknife @BindView绑定布局AndroidX使用
    implementation 'com.jakewharton:butterknife:10.1.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
  • 1
  • 2
  • 3

在这里插入图片描述

使用方法

@BindView(资源ID)
TextView textView;//类型 变量名;

相当于

TextView textView;//类型 变量名;
textView = findViewById(资源ID);
  • 1
  • 2

一定要加上这个!!!!!!!!!!!!!!(不然软件打不开,被怪我-_<)

ButterKnife.bind(this);

Seconed.java文件


import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import butterknife.BindView;
import butterknife.ButterKnife;


public class Seconed extends AppCompatActivity {
    @BindView(R.id.show)
    TextView textView;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
        ButterKnife.bind(this);//一定要加它,防止溢出,否则软件打不开!!!!!!!!!!!!

        textView.setText("隐形跳转");

    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

在这里插入图片描述

就是个偷懒小工具,在此记录一下,基础的使用

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/529690
推荐阅读
相关标签
  

闽ICP备14008679号