赞
踩
替代
findViewById()最基本的使用
,它不会干扰软件运行效率,而且看着高效(通俗点:代码比较干净整洁
)今天新学了个工具库ButterKnife的基础用法
因为我用的是AndroidX,所以只记录AndroidX的配置
build.gradle添加依赖
//butterknife @BindView绑定布局AndroidX使用
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
使用方法
@BindView(资源ID)
TextView textView;//类型 变量名;
相当于
TextView textView;//类型 变量名;
textView = findViewById(资源ID);
一定要加上这个!!!!!!!!!!!!!!(不然软件打不开,被怪我-_<)
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("隐形跳转");
}
}
就是个偷懒小工具,在此记录一下,基础的使用
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。