启动应用程序时,应用程序在启动屏幕之前在黑屏上停止

时间:2019-08-28 07:59:34

标签: android

当我第二次尝试打开应用程序时,它在启动屏幕之前加载的黑屏上停止,并且不加载启动屏幕 我搜索过的链接 blank screen comes before splash

public class SplashActivity extends AppCompatActivity {

SharedPrefs prefs;
ImageView ivSplashLogo;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Crashlytics crashlyticsKit = new Crashlytics.Builder()
            .core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
            .build();

    Fabric.with(this, crashlyticsKit);

    Window window = getWindow();
    WindowManager.LayoutParams winParams = window.getAttributes();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        winParams.flags &= ~WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
    }
    window.setAttributes(winParams);
    window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

    setContentView(R.layout.activity_splash);

    prefs = new SharedPrefs(this);
    prefs.setCount(0);
    ivSplashLogo = findViewById(R.id.iv_splash_logo);
    latestVersionRequest();
}

我的gradle文件是:

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
    minSdkVersion 17
    targetSdkVersion 28
    multiDexEnabled true
    versionCode 61
    versionName "1.0.61"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/ASL2.0'
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

allprojects {
    repositories {
        maven { url "https://jitpack.io" }


    }
}

这是style.xml文件

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:popupMenuStyle">@style/PopupMenu</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="android:textColorSecondary">@color/colorAccent</item>
    <item name="colorControlHighlight">@color/light_grey</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="android:actionMenuTextColor">@color/colorAccent</item>
    <item name="android:actionModeBackground">@color/colorPrimary</item>

    <item name="android:windowAnimationStyle">@null</item>
    <item name="android:windowDisablePreview">true</item>
    <item name="android:windowBackground">@drawable/splash_logo</item>

</style>

<style name="KidsTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorRed</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>


<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Dialog.Alert">
    <!-- Used for the buttons -->
    <item name="colorAccent">#ea7c29</item>
    <!-- Used for the title and text -->
    <item name="android:textColorPrimary">#FFFFFF</item>
    <!-- Used for the background -->
    <item name="android:background">@color/darkColorPrimary</item>
</style>

<style name="tolbar.title" parent="@style/Base.TextAppearance.AppCompat.Title">
    <item name="android:textSize">16sp</item>
    <item name="android:textStyle">bold</item>
</style>

<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/solid_black</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
    <item name="android:textColor">@android:color/white</item>
    <item name="android:itemBackground">@color/black</item>

</style>

<style name="BitrateMenu" parent="@android:style/Widget.PopupMenu">
    <item name="android:textColor">@android:color/white</item>
    <item name="android:itemBackground">@color/black</item>
    <item name="android:textSize">14sp</item>
    <item name="android:listPreferredItemHeightSmall">25dp</item>

</style>


<style name="KidsPopupMenu" parent="@android:style/Widget.PopupMenu">
    <item name="android:textColor">@android:color/black</item>
    <item name="android:itemBackground">@color/white</item>

</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="color">@color/colorAccent</item>
</style>


<style name="MyDarkToolbarStyle" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:colorBackground">@color/black</item>
    <item name="android:textColorSecondary">@color/colorAccent</item>
    <item name="android:textColor">@color/white</item>
</style>


<style name="AlertDialogCustom" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:textColor">@color/colorPrimary</item>
</style>

<style name="SelectableItemTheme">
    <item name="colorControlHighlight">@color/colorAccent</item>
</style>

<style name="SelectableItemThemeWhite">
    <item name="colorControlHighlight">@color/white</item>
</style>

<style name="SelectableItemBackground">
    <item name="android:theme">@style/SelectableItemTheme</item>
    <item name="android:background">?attr/selectableItemBackgroundBorderless</item>
</style>

<style name="SelectableItemBackgroundWhite">
    <item name="android:theme">@style/SelectableItemThemeWhite</item>
    <item name="android:background">?attr/selectableItemBackgroundBorderless</item>
</style>

<style name="OverrideMultipleImageSelectTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="actionModeStyle">@style/OverrideCustomActionModeStyle</item>
    <item name="windowActionModeOverlay">true</item>
</style>

<style name="OverrideCustomActionModeStyle" parent="Base.Widget.AppCompat.ActionMode">
    <item name="background">@color/colorPrimary</item>
</style>

<style name="DialogAnimation">
    <item name="android:windowEnterAnimation">@anim/slide_up</item>
    <item name="android:windowExitAnimation">@anim/slide_bottom</item>
</style>


<style name="AppLoginTheme" parent="Theme.AccountKit">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

它在logcat中没有显示任何错误

2 个答案:

答案 0 :(得分:0)

无法从代码中复制此类问题,但我建议您使用以下技巧:-

  • 将Splash设为启动器活动
  • 几秒钟后,使用处理程序从启动活动导航到另一个活动
  • 与它一起使用Intent标志为SINGLE_TOP和SINGLE_INSTANCE

答案 1 :(得分:0)

有多个解决方案

1。<item name="android:windowAnimationStyle">@null</item>将此设置为您的活动样式

  1. <item name="android:windowDisablePreview">true</item> 将此设置为您的活动样式

  2. <item name="android:windowBackground">@drawable/slash_screen</item> 将此设置为您的活动样式

  3. android:theme="@android:style/Theme.Translucent"

编辑

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:popupMenuStyle">@style/PopupMenu</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:textColorSecondary">@color/colorAccent</item>
<item name="colorControlHighlight">@color/light_grey</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:actionMenuTextColor">@color/colorAccent</item>
<item name="android:actionModeBackground">@color/colorPrimary</item>

 <item name="android:windowDisablePreview">true</item>
</style>

以您的风格使用它并尝试

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);   setContentView(R.layout.activity_splash);

    prefs = new SharedPrefs(this);
    prefs.setCount(0);
    ivSplashLogo = findViewById(R.id.iv_splash_logo);
    latestVersionRequest();
}

将此代码替换为oncreate

希望如此对您有帮助