Android之基础跳转页面

这是登录的页面,非常的简单,用LinearLayout进行布局,一张图片作为背景加三个文本控件、二个文本框、再加上二个按钮,就怎么简单。

在这里插入图片描述

                         图一

在这里插入图片描述

                            图二

这里没有没有,所以点击登录。
代码实现:
activist_main.xml代码,也是图一的代码

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@drawable/b9066ddb"
        android:gravity="center"
        android:paddingTop="220dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="航海王评价系统"
            android:textSize="30sp"
            android:textColor="#FF0099"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal" >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="20dp"
                android:text="账号:"
                android:textSize="30sp" />
            <EditText
                android:id="@+id/name"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:paddingLeft="20dp"
                android:textSize="14sp"
                android:textColor="#CCFFFF"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="20dp"
                android:text="密码:"
                android:textSize="30sp" />
            <EditText
                android:id="@+id/password"
                android:layout_width="match_parent"
                android:layout_height="50dp"

                android:paddingLeft="20dp"
                android:textColor="#CCFFFF"
                android:textSize="14sp" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
            <Button
                android:id="@+id/login_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="80dp"
                android:layout_marginRight="20dp"
                android:gravity="center"
                android:text="登 陆"
                android:textColor="#ffffffff"
                android:background="#1111"
                android:textSize="16sp" />
            <Button
                android:id="@+id/login_button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="40dp"
                android:layout_marginRight="20dp"
                android:gravity="center"
                android:text="注 册"
                android:background="#1111"
                android:textColor="#ffffffff"
                android:textSize="16sp" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="bottom"
            android:orientation="horizontal" >
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

activist_zhuye.xml代码,登录后图二的代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/b9066ddb"
        android:orientation="vertical"
        android:gravity="center">
        <TextView
            android:id="@+id/tv1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="测试登录"
            android:textSize="80dp"
           android:textColor="#FF0099"/>
    </LinearLayout>
</LinearLayout>

MainActivity.java代码 点击登录按钮事件

package com.example.cshi;
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;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
    public Button bt;
    public Button bt1;
    public EditText name;
    public EditText password;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bt =  findViewById(R.id.login_button);
        bt1 =  findViewById(R.id.login_button1);
        name =findViewById(R.id.name);
        password=findViewById(R.id.password);
        //设置控件事件
        setViewListener();
    }
    private void setViewListener() {
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,ZhuCActivity.class);
                startActivity(intent);
            }
        });
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle= new Bundle();
                bundle.putString("name", String.valueOf(name));
                bundle.putString("password", String.valueOf(password));
                Intent intent=new Intent();
                intent.putExtras(bundle);// 封装数据准备传递
                intent.setClass(MainActivity.this,ZhuYeActivity.class);
                startActivity(intent);
            }
        });
    }
}

ZhuYeActivity.java代码,这是跳转图二的事件

package com.example.cshi;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class ZhuYeActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置页面布局
        setContentView(R.layout.activity_zhuye);
}
}
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值