2024/04/05(2024春季)
学习时长:1小时
代码行数:100左右
博客数量:1篇
今天开始完成个人作业的老师进入入口和操作界面。
<?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:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivityTeacherMain" android:gravity="center"> <LinearLayout android:layout_width="260sp" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center"> <Button android:id="@+id/total" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30sp" android:text="@string/total"> </Button> <Space android:layout_width="match_parent" android:layout_height="30sp"> </Space> <Button android:id="@+id/everyday" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30sp" android:text="@string/everyday"> </Button> <Space android:layout_width="match_parent" android:layout_height="30sp"> </Space> <Button android:id="@+id/everyone" android:text="@string/everyone" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="30sp"> </Button> </LinearLayout> </LinearLayout>
package com.example.myapplication; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; public class MainActivityTeacherMain extends AppCompatActivity { private Button total; private Button every_day; private Button every_one; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_teachermain); init(); total.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(MainActivityTeacherMain.this, MainActivityTotal.class)); } }); every_day.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(MainActivityTeacherMain.this, MainActivityEveryday.class)); } }); every_one.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(MainActivityTeacherMain.this, MainActivityEveryone.class)); } }); } private void init() { total=findViewById(R.id.total); every_day=findViewById(R.id.everyday); every_one=findViewById(R.id.everyone); } }