浅谈Android ButterKnife框架的使用,一名毕业三年的女程序媛面试头条经验


三、效果演示


  1. TextView的文本更改为“我爱学习”。点击CheckBox,弹出Toast提示

在这里插入图片描述

  1. 点击button按钮,弹出Toast提示。

在这里插入图片描述


四、完整代码


package com.example.butterknife;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.Button;

import android.widget.CheckBox;

import android.widget.TextView;

import android.widget.Toast;

import butterknife.BindView;

import butterknife.ButterKnife;

import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

// 利用butterknife找到相应的View组件

@BindView(R.id.tv_butterknife)

TextView tvButterknife;

@BindView(R.id.cb_butterknife)

CheckBox cbButterknife;

@BindView(R.id.bt_butterknife)

Button btButterknife;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

ButterKnife.bind(this);

initFunction();

}

// 利用butterknife 生成点击事件

@OnClick({R.id.cb_butterknife, R.id.bt_butterknife})

public void onViewClicked(View view) {

switch (view.getId()) {

case R.id.cb_butterknife:

Toast.makeText(this, “点击了CheckBox”, Toast.LENGTH_SHORT).show();

break;

case R.id.bt_butterknife:

Toast.makeText(this, “点击了Button”, Toast.LENGTH_SHORT).show();

break;

}

}

// 添加初始化函数,处理TextView的显示文本

void initFunction(){

tvButterknife.setText(“我爱学习!”);

}

}

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:app=“http://schemas.android.com/apk/res-auto”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

tools:context=“.MainActivity”

android:orientation=“vertical”

<TextView

android:id=“@+id/tv_butterknife”

android:textSize=“20sp”

android:layout_margin=“10dp”

android:text=“textview”

android:layout_width=“match_parent”

android:layout_height=“wrap_content” />

<CheckBox

android:id=“@+id/cb_butterknife”

android:text=“checkbox”

android:textSize=“20sp”

android:layout_margin=“10dp”

android:layout_width=“match_parent”

android:layout_height=“wrap_content” />

<Button

android:id=“@+id/bt_butterknife”

android:textSize=“20sp”

android:text=“button”

android:layout_width=“match_parent”

android:layout_height=“wrap_content” />


五、其他常用标签


@BindArray 绑定string里面array数组;@BindArray(R.array.city ) String[] citys ;

@BindBitmap 绑定图片资源为Bitmap;@BindBitmap( R.mipmap.wifi ) Bitmap bitmap;

@BindString 绑定一个String id为一个String变量;@BindString( R.string.app_name ) String meg;

@BindColor 绑定color;@BindColor(R.color.colorAccent) int black;

@BindDimen 绑定Dimen;@BindDimen(R.dimen.borth_width) int mBorderWidth;

@BindDrawable 绑定Drawable;@BindDrawable(R.drawable.test_pic) Drawable mTestPic;

@BindFloat 绑定float

@BindInt 绑定int

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)
img

学习分享

在当下这个信息共享的时代,很多资源都可以在网络上找到,只取决于你愿不愿意找或是找的方法对不对了

很多朋友不是没有资料,大多都是有几十上百个G,但是杂乱无章,不知道怎么看从哪看起,甚至是看后就忘

如果大家觉得自己在网上找的资料非常杂乱、不成体系的话,我也分享一套给大家,比较系统,我平常自己也会经常研读。

2021最新上万页的大厂面试真题

image

七大模块学习资料:如NDK模块开发、Android框架体系架构…

image

2021大厂面试真题:

image

只有系统,有方向的学习,才能在短时间内迅速提高自己的技术,只有不断地学习,不懈的努力才能拥有更好的技术,才能在互联网行业中立于不败之地。

套给大家,比较系统,我平常自己也会经常研读。

2021最新上万页的大厂面试真题

[外链图片转存中…(img-QMxRrlTE-1711877914533)]

七大模块学习资料:如NDK模块开发、Android框架体系架构…

[外链图片转存中…(img-9kRx5Qph-1711877914533)]

2021大厂面试真题:

[外链图片转存中…(img-e87TojZk-1711877914534)]

只有系统,有方向的学习,才能在短时间内迅速提高自己的技术,只有不断地学习,不懈的努力才能拥有更好的技术,才能在互联网行业中立于不败之地。

本文已被CODING开源项目:《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》收录

  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值