【问题标题】:animated splash screen doesn't appear动画启动画面不出现
【发布时间】:2020-04-30 10:06:26
【问题描述】:

在这个项目中,我尝试制作一个动画闪屏,它会在进入主活动之前出现,但在我执行之后,闪屏不会出现,而是直接进入主活动。 如何解决这个问题?

这是我的飞溅活动课

    private ImageView container;
    private AnimationDrawable animationDrawable;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash)
        container = findViewById(R.id.iv_icons);
        container.setBackgroundResource(R.drawable.mysplash_animation);

        animationDrawable = (AnimationDrawable) container.getBackground();

    }

    @Override
    protected void onResume() {
        super.onResume();

        animationDrawable.start();

        checkAnimationStatus(50, animationDrawable);
    }

    private void checkAnimationStatus(final int time, final AnimationDrawable animationDrawable) {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (animationDrawable.getCurrent() != animationDrawable.getFrame(animationDrawable.getNumberOfFrames() - 1))
                    checkAnimationStatus(time, animationDrawable);
                else finish();
            }
        }, time);
    }
}

这是我的 manifest.xml

 <application
        android:allowBackup="true"
        android:exported="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.NoActionBar">
        <activity android:name=".SplashActivity"></activity>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

【问题讨论】:

  • 时间变量的值是多少?
  • 能否详细说明您的问题
  • 您的启动活动未设置为默认启动器,所以是的,它不会显示

标签: android xml android-studio android-layout splash-screen


【解决方案1】:

您必须在清单中进行更改(您必须将启动器活动赋予 splashActivity)

    <application
    android:allowBackup="true"
    android:exported="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat.NoActionBar">
    <activity android:name=".SplashActivity">
     // below code you have to add //
    <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
    <activity android:name=".MainActivity">
      //Remove from here//
    </activity>
</application>

【讨论】:

    【解决方案2】:

    将您的 Splash Activity 设置为 Launcher Activity:

     <activity android:name=".MainActivity"></activity>
    
            <activity android:name=".SplashActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
    

    【讨论】:

    • 你的问题现在解决了吗?
    【解决方案3】:

    请向SplashActivity提供intentfilter

    <application
                android:allowBackup="true"
                android:exported="true"
                android:icon="@mipmap/ic_launcher"
                android:label="@string/app_name"
                android:roundIcon="@mipmap/ic_launcher_round"
                android:supportsRtl="true"
                android:theme="@style/Theme.AppCompat.NoActionBar">
                <activity android:name=".SplashActivity">
                       <intent-filter>
                        <action android:name="android.intent.action.MAIN" />
    
                        <category android:name="android.intent.category.LAUNCHER" />
                      </intent-filter>
             </activity>
                <activity android:name=".MainActivity">
    
                </activity>
            </application>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-09
      • 1970-01-01
      • 2022-01-14
      • 1970-01-01
      • 2016-08-06
      • 2019-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多