Android启动画面灰色过渡到活动状态

时间:2020-04-09 09:55:21

标签: android android-layout splash-screen

我目前正在使用Android应用程序,并且添加了一个启动屏幕,在屏幕开头显示徽标。

为了确保初始屏幕停留正确的时间,我使用了将主题应用于初始屏幕活动的方法,然后在相关的Java类中,启动主活动(该活动具有白色背景,与启动画面相同)。初始屏幕可以正确显示并停留适当的时间,但是,当过渡到主要活动时,应用程序将显示灰屏约1秒钟,然后再显示已满载的主要活动。您知道可能是什么问题吗?

这是我正在使用的style.xml文件中的代码:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/Trippy_primary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/Trippy_orange</item>
        <item name="android:textColorPrimary">@color/TrippyGray</item>
        <item name="android:colorBackground">@color/white</item>
        <item name="android:windowAnimationStyle">@null</item>
    </style>

    <style name="SplashTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/Trippy_primary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/Trippy_orange</item>
        <item name="android:textColorPrimary">@color/TrippyGray</item>
        <item name="android:windowBackground">@drawable/splash_screen</item>
        <item name="android:windowAnimationStyle">@null</item>
    </style>
</resources>

这是清单文件中的相应活动标签:

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

这是相关的活动代码:

public class SplashScreen extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.AppTheme);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);

        startActivity(new Intent(this, TrippyList.class).putExtra("comingActivity", false));

        finish();

    }

}

谢谢您的帮助:)

2 个答案:

答案 0 :(得分:0)

试试这个对我有用。

 @Override
 protected void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.AppTheme);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);
        CountDownTimer countDownTimer;
        countDownTimer= new CountDownTimer(2500, 500) {

            public void onTick(long millisUntilFinished) {

            }
            public void onFinish() {

                startActivity(new Intent(SplashScreen.this, TrippyList.class));
                overridePendingTransition(0,0);
                finish();

            }
        }.start();
}

答案 1 :(得分:0)

实际上我发现了问题。我还在应用程序中实现了暗模式,并且在应用程序启动时仍在主要活动中处理用于检测正确模式的代码。在初始屏幕和主要活动之间的事务中看到的背景较暗,可能是因为我的Android系统当前处于黑暗模式。

在初始屏幕中添加暗/亮模式设置可以解决此问题。

相关问题