【问题标题】:Display SplashScreen using Timer使用 Timer 显示 SplashScreen
【发布时间】:2013-07-07 13:50:42
【问题描述】:

我想先在我的应用程序上显示一个 splashScreen 几秒钟,然后使用 java 中的计时器加载我所有的线程数据,然后我应该怎么做。

【问题讨论】:

  • 在 main 方法中,你需要创建一个无边框的 JFrame,它会显示你的启动画面,然后休眠一秒钟,然后继续工作
  • 使用SplashScreen 类讨论here

标签: java


【解决方案1】:

将启动画面活动添加到您的项目... 现在将 SplashScree.java 文件代码替换为:

    package samples.splash.screen;

    import android.app.Activity;
    import android.os.Bundle;
    import android.os.Handler;

    /**
     * Splash screen activity
     *
     * @author Catalin Prata
     */
    public class SplashScreen extends Activity {

        // used to know if the back button was pressed in the splash screen activity and avoid opening the next activity
        private boolean mIsBackButtonPressed;
        private static final int SPLASH_DURATION = 2000; // 2 seconds


        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.splash_screen);

            Handler handler = new Handler();

            // run a thread after 2 seconds to start the home screen
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {

                    // make sure we close the splash screen so the user won't come back when it presses back key

                    finish();

                    if (!mIsBackButtonPressed) {
                        // start the home screen if the back button wasn't pressed already 
                        Intent intent = new Intent(SplashScreen.this, Home.class);
                        SplashScreen.this.startActivity(intent);
                   }

                }

            }, SPLASH_DURATION); // time in milliseconds (1 second = 1000 milliseconds) until the run() method will be called

        }

        @Override
       public void onBackPressed() {

            // set the flag to true so the next activity won't start up
            mIsBackButtonPressed = true;
            super.onBackPressed();

        }

}

splash_screen xml 看起来像这样:您的可绘制对象中应该有任何图像,名称为:“splash_screen”

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="@drawable/splash_screen"/>

现在让您的启动画面成为清单文件中的启动器活动,使其成为启动活动.. 为了让应用程序的标题栏向下,只需在清单中添加他的活动并添加主题,如下所示:

<activity android:name=".SplashScreen" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN">
                <category android:name="android.intent.category.LAUNCHER">
            </category></action></intent-filter>
        </activity>

【讨论】:

  • 谁说这是为 Android 设计的?
【解决方案2】:

请访问以下关于 Java (Swing) 启动画面的优秀教程。

Adding a splash screen to your application

【讨论】:

    猜你喜欢
    • 2014-03-18
    • 2017-09-20
    • 2021-04-10
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-23
    相关资源
    最近更新 更多