移动实验3

  1. 创建项目:

 

  1. 创建activity

 

  1. 编写界面和代码

package com.example.exp3;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    EditText account,password;
    Button login;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initlogin();
    }
    private void initlogin(){
        login=findViewById(R.id.login);
        account=findViewById(R.id.account);
        password=findViewById(R.id.password);
        login.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.login:
                Intent iti=new Intent(this,UIActivity.class);
                iti.putExtra("account",account.getText().toString() );
                iti.putExtra("password",password.getText().toString() );
                startActivity(iti);
                break;
        }
    }
}

 

 

package com.example.exp3;

import androidx.appcompat.app.AppCompatActivity;

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

public class UIActivity extends AppCompatActivity {
    TextView account,password;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_u_i);
        initshow();
    }
    private void initshow(){
        account=findViewById(R.id.accountshow);
        password=findViewById(R.id.passwordshow);
        account.setText(getIntent().getStringExtra("account"));
        password.setText(getIntent().getStringExtra("password"));
    }
}

 

 

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/acconuthang"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/accountwo"
            android:text="账号:"
            android:textColor="@color/black"
            />
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/account"
            android:layout_alignLeft="@id/accountwo"
            android:hint="@string/phone"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/passwordhang"
        android:layout_below="@id/acconuthang"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/passwordwo"
            android:text="密码:"
            android:textColor="@color/black"
            />
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/password"
            android:layout_alignLeft="@id/passwordwo"
            android:hint="请输入密码"
            android:password="true"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/passwordhang">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/login"
            android:text="@string/login"
            android:background="@drawable/login"
            android:layout_marginLeft="40dp"
            />
    </LinearLayout>

</RelativeLayout>

 

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/acconuthang"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="账号: "
            android:textColor="@color/black"
            android:textSize="25dp"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/accountshow"
            android:text="账号"
            android:textColor="@color/black"
            android:textSize="25dp"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="   密码: "
            android:textColor="@color/black"
            android:textSize="25dp"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="25dp"
            android:id="@+id/passwordshow"
            android:text="密码"
            android:textColor="@color/black"
            />
    </LinearLayout>

</RelativeLayout>

 

 

  1. 运行效果

 

posted @ 2022-03-15 08:30  哦心有  阅读(27)  评论(0编辑  收藏  举报