我想为这个应用程序创建启动画面..请帮助我

时间:2013-12-25 10:10:49

标签: android

此代码是我的应用的主页。对于这个应用程序,我想创建启动。

主要应用代码: -

 package com.Wase.edittext;

import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.format.Time;
import android.widget.EditText;

public class Splash extends Activity {

Timer timer = new Timer();

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash_logo);
    Time.schedule(new TimerTask() {
           public void run() {
               Intent intent = new Intent(Splash.this, MyAndroidAppActivity.class);
               startActivity(intent);
               finish();
           }
        }, 5000);
     }
}

这是我的启动代码..请看错误并告诉我..

3 个答案:

答案 0 :(得分:0)

首先创建一个新的XML文件并使用您想要的任何设计,然后创建活动(java)文件并使用下面的代码并根据您的要求更改您的屏幕和变量名称。

public class Splash extends Activity {

Timer timer = new Timer();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    timer.schedule(new TimerTask() {
           public void run() {
               Intent intent = new Intent(Splash.this, MyAndroidAppActivity.class);
               startActivity(intent);
               finish();
           }
        }, 5000);
     }
  }

这是你的splash.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
tools:context=".IMyCompany" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="153dp"
    android:src="@drawable/logo" />

</RelativeLayout>

它将在5秒后移至新活动。

答案 1 :(得分:0)

public class SplashScreen extends Activity {
    public SplashScreen instance;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.xml_splashscreen);
        if (instance != null) {
            instance.finish();
        }
        instance = this;


        Thread threadMenu = new Thread(new Runnable() {
            public void run() {
                try {
                    // sleep 3 second and go next page
                    Thread.sleep(400);
                    // Check Vefication Success then Load HomeScreen Check

                        Intent splash = new Intent(getBaseContext(),
                                MyAndroidAppActivity .class);
                        startActivity(splash);
                        finish();
                        overridePendingTransition(R.anim.push_in_from_left,
                                R.anim.push_out_to_right);



                    }

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        threadMenu.start();
    }
}
清单文件中的

<activity
            android:name="com.demo.SplashScreen"
            android:label="@string/app_name"
            android:screenOrientation="sensorPortait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".com.demo.MyAndroidAppActivity"
            android:configChanges="keyboardHidden"
            android:screenOrientation="sensorPortait"
            android:windowSoftInputMode="stateHidden" />

答案 2 :(得分:0)

use this code
====
public class SplashScreenActivity extends Activity {
    final int splashTimeOut = 3000;
    ImageView imgSplash;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashscreen);
        imgSplash = (ImageView) findViewById(R.id.imgsplash);
        setContentBasedOnLayout();

        // TODO Auto-generated method stub
        Thread splashThread = new Thread() {
            int wait = 0;

            @Override
            public void run() {
                try {
                    super.run();
                    while (wait < splashTimeOut) {
                        sleep(100);
                        wait += 100;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {

                    //If You Want To Do Something Write Here Your Code

                }
            }  
        };
        splashThread.start();
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}