乐学成语之splash

下午写了一篇,结果格式错了,很难看。我再重新编辑一下。

现在很多软件都有一运行就有一个欢迎页面,然后过几秒之后就会转到主页面。我也尝试了一下。其实算不上难,只需要一个XML文件和一个Java文件就可以。将其通过setcontentview连接起来,再导入MP3,通过mediaplayer播放就可以。

项目目录如下:



歌曲我选择的是韩国歌手Aliee的成名曲,给你看。个人觉得比较好,比较动感。嘿嘿。

open.java的代码如下:

package com.example.happyidiom;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;

public class Open extends Activity{
	MediaPlayer oursong;
	
	 private final long SPLASH_LENGTH = 35000;    
     Handler handler = new Handler();  
 public void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.open);
     
     oursong=MediaPlayer.create(Open.this, R.raw.aliee);
     oursong.start();
     
     handler.postDelayed(new Runnable() {  //使用handler的postDelayed实现延时跳转  
     
     
         public void run() {    
             Intent intent = new Intent(Open.this, MainActivity.class);    
             startActivity(intent);    
             finish();       
         }    
     }, SPLASH_LENGTH);//2秒后跳转至应用主界面MainActivity  
       
 }  
 @Override
	protected void onPause() {
		// TODO Auto-generated method stub
		
		super.onPause();
		oursong.stop();
		finish();
	}
	}
这是其中的一种方法,还有另一种方法,但是我不是很熟练。

如下:

package cn.edu.bztc.pop;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;

public class Splah extends Activity{
	MediaPlayer oursong;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);
		
	    oursong=MediaPlayer.create(Splah.this, R.raw.aliee);
		oursong.start();
		
		
		Thread timer=new Thread(){
			public void run(){
				try{
					sleep(35000);
				}catch(InterruptedException e){
					e.printStackTrace();
				}finally{
					Intent open=new Intent("cn.edu.bztc.pop.MENU");
					startActivity(open);
				}
			}
			
		};
		timer.start();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		
		super.onPause();
		oursong.stop();
		finish();
	}

}


个人觉得第一种方法比较简便。方便使用。第二种因为一直显示有错误,我也没有调试出来。


下面是open.xml的页面:


然后再在manifest中加入如下代码:

<activity
            android:name="com.example.happyidiom.Open"
            android:label="open"
            android:theme="@android:style/Theme.NoTitleBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


就可以运行程序了。

就是在启动程序时MP3播放,open页面打开。

之后就跳转到主页面。



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值