Android三个页面制作及跳转

这篇博客详细介绍了如何在Android中创建和跳转三个页面。首先,创建了一个Day01项目,设置了背景图片和线性布局,并隐藏了状态栏和标题。接着,通过线程暂停三秒后进行页面跳转。在MainActivity中,展示了如何重写onCreate方法并实现线程操作。然后,创建了第二个页面,添加了各种控件,并设置了点击事件。最后,创建了第三个页面,展示了如何接收前一个页面的数据并进行显示。文章还提到了常用的Android开发方法,如Toast、findViewById、Intent传值和线程操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先打开ADT程序创建
创建文件如图:
命名Day01

在res-layout中打开activity_main文件,

下面第一个文件为视图,第二个对视图进行编辑

点击第二个,我们要放一个背景图片,插入<LinearLayout>线性布局,并对其定义属性,具体代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/ic_launcher"  
    tools:context=".MainActivity" >
</LinearLayout>


此代码演示将用背景图片将线性布局填充完整,按题目要求走隐藏状态栏和标题并停止界面三秒,打开src对包com.exeample.day01中的Java文件MainActivity进行编辑

定义类MainActivity继承其父类Activity
对方法onCreate方法进行重写


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }    

按要求走在界面停止三秒,运用到线程的知识,
首先new一个Thread类,
1实现Runable接口,重写run方法
2创建Runable子类对象
3然后对界面进行跳转,Intent it = new Intent(A,B);A表示当前文件,B表示跳转界面
4调用Thread()对象的start()方法启动线程

代码演示如下

Thread thread = new Thread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                try {
                    //将此代码进行调控
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //停止三秒后跳转 
                
                Intent it = new Intent(getApplicationContext(),
                        AppActivity.class);
                startActivity(it);
            }
        });
        thread.start();
    }


隐藏状态栏和标题的方法为:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getActionBar().hide();


注意放入代码的位置
jdk小于11会报错。

整合以上三个代码就完成了对MainActivity的编辑

package com.example.day06;

import android.os.Build;
import android.os.Bundle;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.WindowManager;

public class MainActivity extends Activity {

    @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //隐藏状态栏
//        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        //隐藏标题栏
        getActionBar().hide();
        setContentView(R.layout.activity_main);
        
        //开启一个线程(3秒自动跳转)
        Thread t=new Thread(new Runnable() {
			
			@Override
			public void run() {
				// 等待三秒
				try {
					Thread.sleep(3000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				//启动第二个页面
				Intent it = new Intent(getApplicationContext(), 
						LoinActivity.class);
				startActivity(it);
			}
		}) ;
        t.start();
        
        
    }
}

现在对第二个页面的Android页面进行编辑

在项目中新健Android的文件

通过<LinearLayout><TextView><EditText><CheckBox><RadioButtn>等控件对安卓哦安儿页面进行展示

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".LoinActivity" >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#293f47"
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值