Android-第四节01Activity(基础知识)

button.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Log.i(“niming”,“第二次点击按钮”);

}

});

3.获取文本值并判断正误


Toast.makeText()各个参数都是干嘛的

Toast:是一个类,主要管理消息的提示。

makeText(),是Toast的一个方法,用来显示信息,分别有三个参数。

第一个参数:this,是上下文参数,指当前页面显示

第二个参数:“string ”是你想要显示的内容

第三个参数:

Toast.LENGTH_LONG,指显示消息时间长短,另一个是ToastLENGTH_SHORT,大概2秒钟。

show(),表示显示这个Toast消息提醒,当程序运行到这里的时候,就会显示出来,如果不调用show()方法,这个Toast对象存在,但是并不会显示,所以一定不要忘记。

在这里插入图片描述

代码:

package com.hnucm.a_test04;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.ImageView;

import android.widget.TextView;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

TextView textView; //定义textView组件

ImageView imageView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

EditText editText1=findViewById(R.id.editText1);

EditText editText2=findViewById(R.id.editText2);

//通过findViewById

textView=findViewById(R.id.textView1);

textView.setText(“这是修改逻辑代码!”);

textView.setTextSize(20);

textView.setTextColor(getResources().getColor(R.color.black));

imageView=findViewById(R.id.imageView1);

imageView.setImageDrawable(getResources().getDrawable(R.drawable.dzq));

Button button=findViewById(R.id.button);

button.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String username=editText1.getText().toString();

String password=editText2.getText().toString();

if (username.equals(“hnucm”)&&password.equals(“123456”)){

Toast.makeText(MainActivity.this,“登录成功”,Toast.LENGTH_LONG).show();

}

else{

Toast.makeText(MainActivity.this,“登录失败”,Toast.LENGTH_LONG).show();

}

}

});

}

}

4.简单加法计算器


在这里插入图片描述

xml代码:

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

<androidx.constraintlayout.widget.ConstraintLayout 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”>

<TextView

android:id=“@+id/textView1”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:text=“Hello World!”

android:textSize=“50sp”

app:layout_constraintBottom_toBottomOf=“parent”

app:layout_constraintLeft_toLeftOf=“parent”

app:layout_constraintRight_toRightOf=“parent”

app:layout_constraintTop_toTopOf=“parent” />

<ImageView

android:id=“@+id/imageView1”

android:layout_width=“80dp”

android:layout_height=“80dp”

android:layout_marginStart=“32dp”

android:layout_marginTop=“28dp”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toTopOf=“parent”

tools:srcCompat=“@tools:sample/avatars” />

<Button

android:id=“@+id/button”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginTop=“88dp”

android:text=“按钮”

app:layout_constraintEnd_toEndOf=“parent”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toBottomOf=“@+id/textView1” />

<EditText

android:id=“@+id/editText1”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginTop=“24dp”

android:hint=“请输入账号”

app:layout_constraintEnd_toEndOf=“parent”

app:layout_constraintHorizontal_bias=“0.498”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toBottomOf=“@+id/imageView1” />

<EditText

android:id=“@+id/editText2”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:hint=“请输入密码”

app:layout_constraintEnd_toEndOf=“parent”

app:layout_constraintStart_toStartOf=“parent”

app:layout_constraintTop_toBottomOf=“@+id/editText1” />

<TextView

android:id=“@+id/textView”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_marginEnd=“20dp”

android:layout_marginBottom=“4dp”

android:text=“+”

android:textSize=“30dp”

app:layout_constraintBottom_toBottomOf=“parent”

app:layout_constraintEnd_toStartOf=“@+id/editText4” />

<Button

android:id=“@+id/button2”

android:layout_width=“50dp”

android:layout_height=“wrap_content”

android:layout_marginEnd=“156dp”

android:text=“=”

android:textSize=“30dp”

app:layout_constraintBottom_toBottomOf=“parent”

app:layout_constraintEnd_toEndOf=“parent” />

<EditText

android:id=“@+id/editText3”

android:layout_width=“50sp”

android:layout_height=“wrap_content”

app:layout_constraintBottom_toBottomOf=“parent”

app:layout_constraintEnd_toStartOf=“@+id/textView”

app:layout_constraintHorizontal_bias=“0.403”

app:layout_constraintStart_toStartOf=“parent” />

<EditText

android:id=“@+id/editText4”

android:layout_width=“50sp”

android:layout_height=“wrap_content”

android:layout_marginEnd=“20dp”

app:layout_constraintBottom_toBottomOf=“parent”

app:layout_constraintEnd_toStartOf=“@+id/button2” />

<EditText

android:id=“@+id/editText5”

android:layout_width=“50sp”

android:layout_height=“wrap_content”

android:layout_marginEnd=“84dp”

android:layout_marginBottom=“4dp”

app:layout_constraintBottom_toBottomOf=“parent”

app:layout_constraintEnd_toEndOf=“parent” />

</androidx.constraintlayout.widget.ConstraintLayout>

Activity核心代码:

Button button2=findViewById(R.id.button2);

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

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

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

img

img

img

img

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

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

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!**

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

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

[外链图片转存中…(img-PMtmiLAk-1713215837178)]

[外链图片转存中…(img-W4nZ67yZ-1713215837179)]

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

  • 20
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是Android入门知识点的总结: 1. Android基础知识: - Android是一个基于Linux的开源操作系统,主要用于移动设备。 - Android应用程序使用Java编程语言开发。 - Android应用程序由多个组件组成,包括活动(Activity)、服务(Service)、广播接收器(Broadcast Receiver)和内容提供者(Content Provider)。 2. Android应用程序的生命周期: - 活动(Activity)是Android应用程序的用户界面的基本构建块。活动有不同的生命周期状态,如创建、启动、暂停、恢复和销毁。 - 活动的生命周期由回调方法控制,如onCreate()、onStart()、onResume()、onPause()、onStop()和onDestroy()。 3. Android布局: - Android应用程序使用XML文件定义用户界面布局。 - 常用的布局类型包括线性布局(LinearLayout)、相对布局(RelativeLayout)、帧布局(FrameLayout)和约束布局(ConstraintLayout)。 4. Android资源管理: - Android应用程序使用资源文件来存储图像、字符串、颜色等非代码资源。 - 资源文件存储在res目录下,可以通过资源ID在代码中访问。 5. Android意图(Intent): - 意图用于在不同组件之间传递数据和执行操作。 - 显式意图(Explicit Intent)用于启动特定的组件,如活动。 - 隐式意图(Implicit Intent)用于执行系统级操作,如拨打电话、发送短信等。 6. Android存储: - Android应用程序可以使用内部存储和外部存储来保存数据。 - 内部存储用于保存应用程序私有数据,如数据库文件。 - 外部存储用于保存公共数据,如图片、音频和视频文件。 7. Android网络通信: - Android应用程序可以使用HTTP协议进行网络通信。 - 可以使用Android提供的HttpClient类或者使用第三方库,如OkHttp、Volley等。 8. Android数据库: - Android应用程序可以使用SQLite数据库进行数据存储。 - SQLite是一种轻量级的关系型数据库,适用于移动设备。 9. Android权限管理: - Android应用程序需要在清单文件中声明所需的权限。 - 权限用于保护用户的隐私和设备的安全。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值