android教程之用handler实现欢迎界面

一般的应用程序在开启的时候都会有一个绚丽的欢迎界面,让用户在第一眼就爱上这个程序的UI设计,这次我们来自己做一个欢迎界面。

1、  新建一个项目exp,把main.xml改成welcome.xml,添加代码

<?xml version=”1.0″ encoding=”utf-8″?>

<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”

android:orientation=”vertical”

android:layout_width=”fill_parent”

android:layout_height=”fill_parent”

android:background=”@drawable/wel_bg”>

<TextView

android:text=”欢迎”

android:textColor=”#ff0000″

android:textSize=”30px”

android:layout_alignParentBottom=”true”

android:gravity=”center”

android:layout_width=”fill_parent”

android:layout_height=”wrap_content”

/>

</RelativeLayout>

 

2、  在welcome.java中添加代码

package info.mypanz; 

 

 

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.os.Handler;

import android.view.Window;

import android.view.WindowManager;

 

public class welcome extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.welcome);

new Handler().postDelayed(new Runnable(){//新建一个handler实现演示跳转

 

@Override

public void run() {

// TODO Auto-generated method stub

Intent i = new Intent();

i.setClass(welcome.this,login.class);

startActivity(i);

}

},5000);

}

}

3、  新建一个类 login.java,添加布局文件login.xml

<?xml version=”1.0″ encoding=”utf-8″?> 

 

<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”

android:orientation=”vertical”

android:layout_width=”fill_parent”

android:layout_height=”fill_parent”

android:background=”@drawable/bg12″

>

 

<TableLayout

android:layout_height=”180px”

android:id=”@+id/tl1″

android:layout_width=”200px”

 

android:layout_centerHorizontal=”true”

android:layout_centerVertical=”true”

>

<TableRow

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:layout_marginLeft=”20px”

>

<TextView

android:text=”用户名:”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:textColor=”#0000ff”

android:textSize=”15px”

/>

<EditText

android:id=”@+id/login_uname”

android:layout_width=”100px”

android:layout_height=”wrap_content”

/>

</TableRow>

<TableRow

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:layout_marginLeft=”20px”

>

<TextView

android:text=”密码:”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:textColor=”#0000ff”

android:textSize=”15px”

/>

<EditText

android:id=”@+id/login_psw”

android:layout_width=”100px”

android:layout_height=”wrap_content”

android:password=”true”

/>

</TableRow>

<TableRow

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:layout_marginLeft=”20px”

>

<CheckBox

android:id=”@+id/ckpsw”

android:checked=”true”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:text=”记住密码”

android:textColor=”#0000ff”

/>

<Button

android:id=”@+id/login_btn”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:text=”登录”

/>

</TableRow>

<LinearLayout

android:layout_marginLeft=”25px”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:orientation=”vertical”

>

<Button

android:id=”@+id/reg_btn”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:text=”没有账号?注册”

/>

</LinearLayout>

</TableLayout>

 

</RelativeLayout>

 

4、  login.java文件

package eoe.com; 

 

 

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

 

public class login extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.login);

setTitle(“登录”);

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

login_btn.setOnClickListener(new Button.OnClickListener(){

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

Intent loginintent = new Intent();

loginintent.setClass(login.this,main_menu.class);

startActivity(loginintent);

}

});

Button r_btn = (Button) findViewById(R.id.reg_btn);

r_btn.setOnClickListener(new Button.OnClickListener(){

 

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

Intent regintent = new Intent();

regintent.setClass(login.this,reg.class);

startActivity(regintent);

}

 

});

}

}

5、  运行效果

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值