【问题标题】:Android. How to increase splash screen duration?安卓。如何增加启动画面的持续时间?
【发布时间】:2021-05-22 20:32:18
【问题描述】:

我正在使用单一活动方法。我需要显示一个启动画面。为此,我使用以下代码:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_bg</item>
    </style>

在 AndroidManifest 中:

 <activity
            android:theme="@style/SplashTheme"
            android:name=".presentation.app.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

一切正常,但我想稍微增加启动画面的持续时间,可以这样做吗?

【问题讨论】:

    标签: android splash-screen android-theme android-styles


    【解决方案1】:

    你在 Activity 中定义一个 handler 你想像这样延迟:

    public class SplashActivity extends AppCompatActivity {
    
    
        private static int SPLASH_TIME_OUT = 1000;
    
     @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_splash);
    
                new Handler().postDelayed(() -> {
                Intent homeIntent = new Intent(SplashActivity.this, NextActivity.class);
                startActivity(homeIntent);
                finish();
    
            },SPLASH_TIME_OUT);
        }
    

    1 秒 = 1000 就像在这个例子中一样。干杯:)

    别忘了将您的Splashactivity 添加到您的AndroidManifest.xml

    <activity android:name="com.example.Dex7raCryptoAlert.Main.SplashActivity"
    

    【讨论】:

    • 感谢您的回复。但我不想为启动画面创建一个单独的活动。我想也许有一些方法可以使用我提供的方法来解决我的问题
    • 让我看看我发现了什么,但我建议为启动画面做一个活动。它可以比您的选择更加定制。
    • 我的,下面帖子的第二个答案是要走的路:stackoverflow.com/questions/5486789/… 祝你好运。你的问题现在应该回答了:)
    猜你喜欢
    • 2022-12-28
    • 1970-01-01
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    相关资源
    最近更新 更多