①、先建立一个activaty去部署我们的登陆界面
1 package com.example.administrator.actionbardemo; 2 3 import android.app.Activity; 4 import android.content.Intent; 5 import android.os.Bundle; 6 import android.view.View; 7 import android.widget.Button; 8 import android.widget.EditText; 9 import android.widget.TextView; 10 import android.widget.Toast; 11 12 public class MainActivity extends Activity { 13 14 private Button denglu; //登录按钮 15 private TextView new_user; //新用户连接 16 17 private String user = "111111"; //用户名 18 private String possword = "111111"; //用户密码 19 @Override 20 protected void onCreate(Bundle savedInstanceState) { 21 super.onCreate(savedInstanceState); 22 setContentView(R.layout.activity_main); 23 24 denglu = (Button) findViewById(R.id.denglu); //绑定 按钮 25 //登录按钮的监听事件 26 denglu.setOnClickListener(new View.OnClickListener() { 27 @Override 28 public void onClick(View v) { 29 EditText user_name = (EditText) findViewById(R.id.user_name); //绑定 用户名 编辑框 30 EditText pwd = (EditText) findViewById(R.id.pwd); //绑定 密码 输入框 31 if(pwd.getText().toString().equals(possword) && user_name.getText().toString().equals(user)){ 32 Intent intent = new Intent(MainActivity.this,CopyProgressBarDemo.class); //绑定Activaty 33 startActivity(intent); //启动Activity 34 Toast.makeText(getApplicationContext(),"登陆成功",Toast.LENGTH_SHORT).show(); 35 // finish(); //结束本Activity 36 }else{ 37 Toast.makeText(getApplicationContext(),"用户名或密码不正确",Toast.LENGTH_SHORT).show(); 38 } 39 40 } 41 }); 42 new_user = (TextView) findViewById(R.id.new_user); //绑定 新用户 TextView 43 //绑定监听事件 44 new_user.setOnClickListener(new View.OnClickListener() { 45 @Override 46 public void onClick(View v) { 47 Intent intent = new Intent(MainActivity.this,Zhuce.class); 48 startActivity(intent); 49 } 50 }); 51 52 } 53 }
这里是MainActivity的布局xml文件
<LinearLayoutxmlns: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"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"android:paddingBottom="@dimen/activity_vertical_margin"android:background="@drawable/login_backgrond"tools:context=".MainActivity"><EditTextandroid:id="@+id/user_name"android:layout_width="220dp"android:layout_height="40dp"android:layout_gravity="center_horizontal"android:layout_marginTop="80dp"android:singleLine="true"android:drawableLeft="@drawable/denglu_per"android:background="@drawable/edit_text_shape"android:hint="请输入用户帐号"/><EditTextandroid:id="@+id/pwd"android:layout_width="220dp"android:layout_height="40dp"android:layout_gravity="center_horizontal"android:layout_marginTop="15dp"android:password="true"android:singleLine="true"android:drawableLeft="@drawable/denglu_lock"android:background="@drawable/edit_text_shape"android:hint="请输入用户密码"/><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_gravity="center_horizontal"><CheckBoxandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="记住密码"android:checked="true"/><CheckBoxandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="自动登录"android:checked="false"/></LinearLayout><Buttonandroid:id="@+id/denglu"android:layout_width="200dp"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:layout_marginTop="20dp"android:text="登录"android:textSize="24dp"android:background="@drawable/button_type"/><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="match_parent"android:layout_gravity="right|end"android:orientation="horizontal"><TextViewandroid:id="@+id/forget_pwd"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="bottom"android:text="忘记密码"android:textColor="#00F9FF"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text=" | "android:layout_gravity="bottom"/><TextViewandroid:id="@+id/new_user"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="新用户"android:layout_gravity="bottom"android:textColor="#00F9FF"/></LinearLayout> </LinearLayout>
②、新建一个Activity,在这个Activity中,我加入了一个耗时操作去模拟。
1 package com.example.administrator.actionbardemo; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.os.Handler; 6 import android.os.Message; 7 import android.view.Window; 8 9 import java.util.Timer; 10 import java.util.TimerTask; 11 12 public class CopyProgressBarDemo extends Activity { 13 14 @Override 15 protected void onCreate(Bundle savedInstanceState) { 16 super.onCreate(savedInstanceState); 17 this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏 18 setContentView(R.layout.activity_login_susccess); 19 20 CopyProgressBarDemo.this.setFinishOnTouchOutside(false); //窗口 activity 点击空白 不取消 21 22 final Handler myHandler = new Handler(){ 23 @Override 24 public void handleMessage(Message msg) { 25 super.handleMessage(msg); 26 if (msg.what == 0x111){ 27 finish(); 28 } 29 } 30 }; 31 32 //定义一个计时器,让该计时器周期性的执行指定任务 33 final int[] count = {0}; 34 new Timer().schedule(new TimerTask() { 35 @Override 36 public void run() { 37 count[0]++; 38 if(count[0] == 10){ 39 myHandler.sendEmptyMessage(0x111); 40 } 41 } 42 },0,500); 43 44 } 45 }
布局文件,该文件只包含了一个progressBar和一个TextView
<LinearLayoutxmlns: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="horizontal"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"android:paddingBottom="@dimen/activity_vertical_margin"tools:context="com.example.administrator.actionbardemo.LoginSuscceWss"><ProgressBarandroid:layout_width="wrap_content"android:layout_height="wrap_content"style="@android:style/Widget.ProgressBar.Small"/><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="请等待..."/></LinearLayout>
效果图: