Splash闪屏页的使用方法
来源:互联网 发布:重庆seo服务 编辑:程序博客网 时间:2024/06/07 01:35
方法一(静态):使用Handler,在handleMessage中使用Intent实现跳转
MainActivity
package com.example.forherplayer;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.os.Handler;import android.os.Message;public class SplashActivity extends Activity {private static final int START_ACTIVITY = 0x1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); handler.sendEmptyMessageDelayed(START_ACTIVITY, 3000); } private Handler handler = new Handler(){ public void handleMessage(Message msg) { switch(msg.what){ case START_ACTIVITY: startActivity(new Intent(SplashActivity.this,MainActivity.class)); finish(); break; } }; };}
其他代码与下文相同,详见方法二
方法二(动态):使用AlphaAnimation,在监听最后结束动画后实现Intent跳转
MainActivity
package com.example.splashtestdemo;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.view.animation.AlphaAnimation;import android.view.animation.Animation;import android.view.animation.Animation.AnimationListener;import android.widget.ImageView;/* * 方法一:静态闪屏页 * 使用Handler,在handleMessage中实现Intent跳转 *///public class SplashActivity extends Activity {////private static final int START_ACTIVITY = 0x1;// @Override// protected void onCreate(Bundle savedInstanceState) {// super.onCreate(savedInstanceState);// setContentView(R.layout.activity_splash);// handler.sendEmptyMessageDelayed(START_ACTIVITY, 3000);// }////// private Handler handler = new Handler(){// public void handleMessage(Message msg) {// switch(msg.what){// case START_ACTIVITY:// startActivity(new Intent(SplashActivity.this,MainActivity.class));// finish();// break;// }// };// };//}/* * 方法二:动态闪屏页 * 使用AlphaAnimation,在监听最后结束动画后实现Intent跳转 */public class SplashActivity extends Activity { private ImageView iv_splash; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //添加去标题和隐藏状态栏代码,测试时发现标题与状态栏瞬间状态可视,建议在清单文件SplashActivity的them添加为 //android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"// //去标题// requestWindowFeature(Window.FEATURE_NO_TITLE);// //隐藏状态栏// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_splash); iv_splash = (ImageView) findViewById(R.id.iv_splash); //设置透明度动画由10%到100% AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f, 1.0f); //设置动画时长3秒 alphaAnimation.setDuration(3000); //开始动画 iv_splash.startAnimation(alphaAnimation); //为动画设置监听器 alphaAnimation.setAnimationListener(new AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {// TODO Auto-generated method stub}@Overridepublic void onAnimationRepeat(Animation animation) {// TODO Auto-generated method stub}@Overridepublic void onAnimationEnd(Animation animation) {// TODO Auto-generated method stubstartActivity(new Intent(SplashActivity.this,MainActivity.class));finish();}}); } }
activity_splash
<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" tools:context="com.example.splashtestdemo.SplashActivity" > <ImageView android:id="@+id/iv_splash" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/splash" android:scaleType="centerCrop" /></LinearLayout>
跳转后的MainActivity
package com.example.splashtestdemo;import android.app.Activity;import android.os.Bundle;public class MainActivity extends Activity{@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}}
activity_main
<?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" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="10dp" android:text="账号" android:textSize="16sp" /> <AutoCompleteTextView android:id="@+id/user" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:completionThreshold="1" android:inputType="textEmailAddress" android:singleLine="true" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="10dp" android:text="密码" android:textSize="16sp" /> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:password="true" android:singleLine="true" /> <Button android:id="@+id/loginButton" android:layout_width="180dp" android:layout_height="50dp" android:layout_gravity="center_horizontal" android:dividerHeight="2.0dp" android:text="登陆" /></LinearLayout>
AndroidManifest
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.splashtestdemo" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="18" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".SplashActivity" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity"></activity> </application></manifest>
由于没有找到合适手机gif截屏app,所以不上传效果图了,然而闪屏页素材还是可以上传的
参考:http://blog.csdn.net/junjunguoguo/article/details/7798796
加餐:http://blog.csdn.net/u011067360/article/details/24176679?utm_source=tuicool&utm_medium=referral
http://blog.csdn.net/ye_scofield/article/details/43269311
http://blog.csdn.net/wangjinyu501/article/details/7643396
0 0
- Splash闪屏页的使用方法
- Splash.cs的改进
- android的Splash Screen
- Splash界面的实现
- 应用程序的splash界面
- Splash的实现
- Splash/Welcome的作用
- Splash的实现
- 【Android】Splash的使用
- Splash 闪屏页开发
- splash
- splash
- Splash
- Splash窗体的完美实现
- 如何替换eclipse的Splash
- android的splash启动画面
- 与splash详解相关的
- Splash页面的跳转逻辑
- C语言字符串转换为oc
- 【剑指offer系列】 复杂链表的复制___26
- jdk1.6容器-LinkedList源码
- Mybatis分页
- 线程饥饿死锁
- Splash闪屏页的使用方法
- JSON转为字典
- apt-get install E: Encountered a section with no Package: header 解决办法
- Double-Lock Checking
- 基于NodeBB的网站服务器迁移步骤
- Class不是对象,用assign修饰
- Android ListView 下拉刷新
- Scrapy 默认设置
- BestCoder Round #79 (div.2)-jrMz and angles,,暴力求解~