Android实现闪屏及注册和登录界面之间的切换效果

在没给大家介绍正文之前先给大家说下实现思路:

先分别实现闪屏、注册界面、登录界面的活动,再用Intent将相关的活动连接起来,实现不同活动之间的跳转。此次试验代码较多,我只列出主要代码,详细的代码可用底部的下载链接下载。

一、实验效果图:

二、主要代码:

(1)WelcomeActivity.Java(这部分代码实现的是第一页的欢迎页面)

package com.example.flashscreendemo; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.RotateAnimation; import android.widget.ImageView; import android.widget.RelativeLayout; public class WeclomeActivity extends Activity { private RelativeLayout layoutWecome; private ImageView ivMonkey; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* * requestWindowFeature(Window.FEATURE_NO_TITLE); //取消电量状态栏 * this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, * WindowManager.LayoutParams.FLAG_FULLSCREEN); */ setContentView(R.layout.activity_weclome); layoutWecome = (RelativeLayout) findViewById(R.id.layoutWelcome); AlphaAnimation alphaAnimation = new AlphaAnimation(0.0f, 1.0f); alphaAnimation.setDuration(1000); layoutWecome.startAnimation(alphaAnimation); ivMonkey = (ImageView) findViewById(R.id.ivMonkey); RotateAnimation rotateAnimation = new RotateAnimation(0, 360); rotateAnimation.setDuration(2000); rotateAnimation.setRepeatCount(2); ivMonkey.startAnimation(rotateAnimation); rotateAnimation.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { Intent intent = new Intent(WeclomeActivity.this, GuideActivity.class); startActivity(intent); finish(); } }); } }

(2)GuideActivity.java(这部分代码实现的是四个引导界面的功能)

package com.example.flashscreendemo; import java.util.ArrayList; import java.util.List; import com.example.flashscreendemo.adapter.GuideAdapter; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.view.LayoutInflater; import android.view.Menu; import android.view.View; import android.widget.ImageView; public class GuideActivity extends Activity { private ViewPager vpGuide; private ImageView ivDots[]; private int[] dots_id; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_guide); initGuideViews(); initDots(); vpGuide.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageSelected(int position) { for (int i = 0; i < ivDots.length; i++) { if (position == i) { ivDots[i] .setImageResource(R.drawable.bg_point_selected); } else { ivDots[i].setImageResource(R.drawable.bg_point_normal); } } } @Override public void onPageScrolled(int position, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int postion) { } }); } public void jumpMain(View view) { Intent intent = new Intent(this, com.example.minitwittersimulate.LoginActivity.class); startActivity(intent); finish(); } private void initDots() { dots_id = new int[] { R.id.ivDots1, R.id.ivDots2, R.id.ivDots3, R.id.ivDots4 }; ivDots = new ImageView[dots_id.length]; for (int i = 0; i < ivDots.length; i++) { ivDots[i] = (ImageView) findViewById(dots_id[i]); } } private void initGuideViews() { vpGuide = (ViewPager) findViewById(R.id.vpGuide); List<View> views = new ArrayList<View>(); LayoutInflater layoutInflater = getLayoutInflater(); View view1 = layoutInflater.inflate(R.layout.view1ofpager, null); views.add(view1); View view2 = layoutInflater.inflate(R.layout.view2ofpager, null); views.add(view2); View view3 = layoutInflater.inflate(R.layout.view3ofpager, null); views.add(view3); View view4 = layoutInflater.inflate(R.layout.view4ofpager, null); views.add(view4); GuideAdapter guideAdapter = new GuideAdapter(views); vpGuide.setAdapter(guideAdapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.guide, menu); return true; } }

(3)GuideAdapter.java(这部分代码实现的是数据适配的功能)

package com.example.flashscreendemo.adapter; import java.util.List; import android.support.v4.view.PagerAdapter; import android.view.View; import android.view.ViewGroup; public class GuideAdapter extends PagerAdapter { private List<View> views; public GuideAdapter(List<View> views) { super(); this.views = views; } @Override public int getCount() { return views.size(); } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } @Override public Object instantiateItem(ViewGroup container, int position) { container.addView(views.get(position)); return views.get(position); } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView(views.get(position)); } }

(4)LoginActivity.java(这部分代码是登录界面的实现)

package com.example.minitwittersimulate; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.example.flashscreendemo.R; public class LoginActivity extends Activity { private SharedPreferences pref; private SharedPreferences.Editor editor; private EditText etUsername; private EditText etPassword; private Button btnLogin; private CheckBox cbRememberPass; private TextView tvRe; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); pref = PreferenceManager.getDefaultSharedPreferences(this); etUsername = (EditText) findViewById(R.id.etUsername); etPassword = (EditText) findViewById(R.id.etPassword); cbRememberPass = (CheckBox) findViewById(R.id.cbRememberPass); btnLogin = (Button) findViewById(R.id.btnLogin); tvRe = (TextView) findViewById(R.id.tvRe); boolean isRemember = pref.getBoolean("remember_password", false); if (isRemember) {// 将账号和密码都设置到文本框中 String account = pref.getString("account", ""); String password = pref.getString("password", ""); etUsername.setText(account); etPassword.setText(password); cbRememberPass.setChecked(true); } btnLogin.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String account = etUsername.getText().toString(); String password = etPassword.getText().toString(); if (account.trim().equals("")) { Toast.makeText(LoginActivity.this, "请您输入用户名!", Toast.LENGTH_SHORT).show(); return; } if (password.trim().equals("")) { Toast.makeText(LoginActivity.this, "请您输入密码!", Toast.LENGTH_SHORT).show(); return; } if (account.equals("admin") && password.equals("123456")) { editor = pref.edit(); if (cbRememberPass.isChecked()) {// 检查复选框是否被选中 editor.putBoolean("remember_password", true); editor.putString("account", account); editor.putString("password", password); } else { editor.clear(); } editor.commit(); Intent intent = new Intent(LoginActivity.this, MainActivity.class); startActivity(intent); finish(); } else { Toast.makeText(LoginActivity.this, "account or password is invalid", Toast.LENGTH_SHORT).show(); } } }); tvRe.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(LoginActivity.this, Register.class); startActivity(intent); finish(); } }); } }

(5)User.java(这部分代码实现向注册界面传入用户输入的数据)

package com.example.minitwittersimulate; public class User { private String userName; private String passWord; private char sex; private String city; private String hobby; public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getPassWord() { return passWord; } public void setPassWord(String passWord) { this.passWord = passWord; } public char getSex() { return sex; } public void setSex(char sex) { this.sex = sex; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getHobby() { return hobby; } public void setHobby(String hobby) { this.hobby = hobby; } public User(String userName, String passWord, char sex, String city, String hobby) { super(); this.userName = userName; this.passWord = passWord; this.sex = sex; this.city = city; this.hobby = hobby; } @Override public String toString() { // TODO Auto-generated method stub return this.userName + "," + this.passWord + "," + this.sex + "," + this.city + "," + this.hobby; } }

(6)Register.java(这部分代码是注册界面的实现)

package com.example.minitwittersimulate; import com.example.flashscreendemo.R; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.widget.CheckBox; import android.widget.EditText; import android.widget.RadioButton; import android.widget.Spinner; import android.widget.Toast; public class Register extends Activity { EditText etUser, etPassw, etRePassw; RadioButton rbMale, rbfaMale; CheckBox cbRead, cbTourist, cbPlayGame; Spinner spCity; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); init(); } private void init() { // TODO Auto-generated method stub etUser = (EditText) findViewById(R.id.etUser); etPassw = (EditText) findViewById(R.id.etPassw); etRePassw = (EditText) findViewById(R.id.etRePassw); rbMale = (RadioButton) findViewById(R.id.rbMale); rbfaMale = (RadioButton) findViewById(R.id.rbfaMale); cbRead = (CheckBox) findViewById(R.id.cbRead); cbTourist = (CheckBox) findViewById(R.id.cbTourist); cbPlayGame = (CheckBox) findViewById(R.id.cbPlayGame); spCity = (Spinner) findViewById(R.id.spCity); } public void onclick(View view) { switch (view.getId()) { case R.id.btRegister: String userName = etUser.getText().toString(); if (TextUtils.isEmpty(userName)) { Toast.makeText(this, "用户名不能为空", 2000).show(); return; } String passW = etPassw.getText().toString(); if (TextUtils.isEmpty(passW)) { etPassw.setError("密码不能为空"); return; } String rePassw = etRePassw.getText().toString(); if (TextUtils.isEmpty(rePassw)) { etRePassw.setError("确认密码不能为空"); return; } if (!passW.equals(rePassw)) { Toast.makeText(this, "两次密码不一致", 2000).show(); return; } char sex; if (rbMale.isChecked()) { sex = rbMale.getText().charAt(0); } else { sex = rbfaMale.getText().charAt(0); } StringBuffer s = new StringBuffer(); if (cbRead.isChecked()) { s.append(cbRead.getText().toString() + ","); } if (cbTourist.isChecked()) { s.append(cbTourist.getText().toString() + ","); } if (cbPlayGame.isChecked()) { s.append(cbPlayGame.getText().toString() + ","); } String city = spCity.getSelectedItem().toString(); User user = new User(userName, passW, sex, s.toString().equals("") ? "" : s.toString().substring(0, s.length()), city); Toast.makeText(this, "用户注册信息:" + user.toString(), 100000).show(); Intent intent = new Intent(Register.this, LoginActivity.class); startActivity(intent); finish(); break; case R.id.btEixt: finish(); break; case R.id.btReturn: Intent intent1 = new Intent(Register.this, LoginActivity.class); startActivity(intent1); finish(); break; } } }

(7)MainActivity.java(这部分代码实现的是点击“登录”按钮后跳转到的界面)

package com.example.minitwittersimulate; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import com.example.flashscreendemo.R; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }

以上所述是小编给大家介绍的Android实现闪屏及注册和登录界面之间的切换效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

时间: 2024-09-20 08:01:26

Android实现闪屏及注册和登录界面之间的切换效果的相关文章

Android实现闪屏及注册和登录界面之间的切换效果_Android

在没给大家介绍正文之前先给大家说下实现思路: 先分别实现闪屏.注册界面.登录界面的活动,再用Intent将相关的活动连接起来,实现不同活动之间的跳转.此次试验代码较多,我只列出主要代码,详细的代码可用底部的下载链接下载. 一.实验效果图: 二.主要代码: (1)WelcomeActivity.Java(这部分代码实现的是第一页的欢迎页面) package com.example.flashscreendemo; import android.app.Activity; import androi

Android应用闪屏页延迟跳转的三种写法

闪屏页也称之为欢迎页.在打开一个App时,我们第一眼看到的往往是一个闪屏页面,之所以叫闪屏页,是因为它出现之后会短暂地停留几秒钟再跳转到其他页面.闪屏页除了使用户体验更好外,还能给app留出初始化数据的时间.下面,是我总结的闪屏页的三种写法. 准备工作 打开Android Studio,新建一个projectMyStudy,新建一个SplashActivity并在清单文件中将其设置为启动Activity.在布局文件中将SplashActivity的背景设置为一张图片(可以是手机壁纸). <?xm

Android中闪屏实现方法小结(普通闪屏、倒计时闪屏、倒计时+动画闪屏)

一.项目目录结构 二.activity_main.xml代码 <RelativeLayout 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

Android 自定义闪屏页广告倒计时view效果

如今APP越来越多,我们每天所使用的的软件也越来越多,可是在我们不付费的情况下,App制造商如何实现,实现收入甚至是盈利呢?答案就是在我们打开软件所必须经过的地方穿插广告,当然为了顾及用户的感受,一般都会以倒计时的形式展示给用户,用户可以选择跳过.可能是因为自己的强迫症,总想着是怎么做的,自己就尝试了一下,分享给大家的同时,顺便加深自己的理解.效果如图: 1.为了满足产品和设计,先搞几个自定义属性 1)内层背景 2)数字的颜色 3)外层圆环宽度 4)文字大小 5)外层圆环颜色 6)圆的半径 这里

php注册和登录界面的实现案例(推荐)_php实例

当初我觉得一个网站上注册和登录这两个功能很神奇,后来自己研究一下发现其实道理很简单,接下来看一下怎么实现的吧.... 我在我的电脑上建了几个文件: login.html (登录页面) register.html(注册页面) success.html(登录成功跳转页面) return.html(注册成功页面) login.php register.php 登录界面和注册界面以及success.html并没有 什么都是些html标记如下: <html> <head> <meta

Android 实现闪屏页和右上角的倒计时跳转实例代码_Android

以前编程的时候,遇到倒计时的功能时,经常自己去写,但其实Android已经帮封装好了一个倒计时类CountDownTimer,其实是将后台线程的创建和Handler队列封装成为了一个方便的类调用. 闪屏页用到了handler和CountDownTimer类,还需配置一下Activity的主题,这里是:android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 全屏主题的意思. 给大家展示下效果图: 代码如下所示: package

Android 实现闪屏页和右上角的倒计时跳转实例代码

以前编程的时候,遇到倒计时的功能时,经常自己去写,但其实Android已经帮封装好了一个倒计时类CountDownTimer,其实是将后台线程的创建和Handler队列封装成为了一个方便的类调用. 闪屏页用到了handler和CountDownTimer类,还需配置一下Activity的主题,这里是:android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 全屏主题的意思. 给大家展示下效果图: 代码如下所示: package

Android实现闪屏欢迎界面

闪屏:在打开App时,展示,持续数秒后,自动关闭,进入另外的一个界面,SplashActivity跳转到MainActivity Android中有三种实现方法 xml代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q

Android属性动画实现炫酷的登录界面

我们聊聊我们常写的登录界面,这个界面我相信很多人都写过,而且也没什么难度,但是如果要实现比较不一般的效果,那就要花点心思了,先看看项目的效果吧: 我一直都不知道怎么在编辑框连设置图片大小,所以这个图不怎么样适配编辑框了,大家先凑合着看看. 我先讲讲思路,当我们输入完账号跟密码之后,点击登录,那这个输入框就慢慢的消失,在消失后,紧接着就出现这个进度的界面. 思路有了,那我们就开始编码了: 新建一个项目,然后系统生成了一个MainActivity.java文件和activity_main.xml文件