【问题标题】:Black screen appears before splash screen闪屏前出现黑屏
【发布时间】:2016-02-03 15:23:13
【问题描述】:

当我启动我的应用程序时,出现片刻黑屏,然后只出现启动画面。我遵循了this 线程中的一些解决方案,但没有任何效果。它的实际原因可能是什么?谁能帮忙?我已经粘贴了下面的代码。

SplashScreenActivity.java

public class SplashScreenActivity extends Activity {

    private static final int SPLASH_TIME_OUT = 3 * 1000;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_splash);

        Util.doGuestLoginAndCheckForExpireDate();

        UserDetail.deleteUserDetailJson();
        Util.setProfileFetchStatus(false);
        // Start animating the image
        final ImageView splash = (ImageView) findViewById(R.id.logoImageViw);

       final  TranslateAnimation anim = new TranslateAnimation(0f, 0f, 1200f, 0f);
        anim.setDuration(1200);
        anim.setFillAfter(true);

        splash.startAnimation(anim);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                splash.setAnimation(anim);

                if (Util.getLoginStatus()) {
                    startActivity(new Intent(SplashScreenActivity.this, RestActivity.class));
                } else
                    startActivity(new Intent(SplashScreenActivity.this, AppIntroduction.class));

                finish();

            }
        }, SPLASH_TIME_OUT);

    }
}

这是theme 我已包含在Application tag 内的Android manifest.xml 文件中

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">@color/primary_color</item>
    <item name="windowNoTitle">true</item>
    <item name="colorAccent">@color/primary_color</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

我在这里做错了吗??

【问题讨论】:

  • 评论动画部分并查看
  • @MaheshwarLigade 做到了,但仍然是同样的问题。
  • 检查ImageView初始化之前调用的方法可能是他们需要很长时间才能完成各自的任务
  • @JiteshDalsaniya 我尝试通过注释图像视图部分初始化上面的所有行来运行应用程序,但问题仍然存在
  • Runnable 的 run 方法中的代码将 ui 更新代码放入 runOnUIThread 方法中然后检查。

标签: android splash-screen


【解决方案1】:

在创建主要活动之前,您将根据所选主题看到黑色或白色,以减少时间不要在 onCreate 中做任何激烈的事情,只需设置布局即可将代码移动到 onStart() 或 onResume()在链接的线程中,您还看到他设置了 android:windowBackground 来设置加载时活动的初始背景,可以是静态图像或颜色

【讨论】:

    【解决方案2】:

    我在更新 gradle 时遇到了这个问题,我把它改回 prebeta 版本来修复它。 来自:

    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0-beta1'
    }
    

    收件人:

    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
    }
    

    【讨论】:

      猜你喜欢
      • 2011-07-20
      • 2021-01-04
      • 1970-01-01
      • 2017-10-03
      • 2021-03-18
      • 2015-08-01
      • 1970-01-01
      • 2022-10-05
      • 2018-12-11
      相关资源
      最近更新 更多