如何在Android中显示闪屏?

How do I show a splash screen in Android?(如何在Android中显示闪屏?)

本文介绍了如何在Android中显示闪屏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在应用程序加载时显示闪屏,这是我的Java代码:

ImageView splash = (ImageView) this.findViewById(R.id.splashscreen);

splash.postDelayed(new Runnable(){
    splash.setVisibility(View.GONE);
}, 3000);

但我在postDelayed()调用中收到错误"无法解析符号"。我还收到了"意外令牌"

}, 3000);

最后,这是我的布局:

<TextView
    android:text="@string/hello_world"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<ImageView
    android:id="@+id/splashscreen"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:src="@drawable/splash"
    android:layout_gravity="center"/> 

日志:

9:41:01 PM Throwable
       Read access is allowed from event dispatch thread or inside read-action only (see com.intellij.openapi.application.Application.runReadAction())
       Details: Current thread: Thread[ApplicationImpl pooled thread 239,4,main] 359404630
       Our dispatch thread:Thread[AWT-EventQueue-0 0.4.2#AI-133.970939, eap:true,6,main] 1198871553
       SystemEventQueueThread: Thread[AWT-EventQueue-0 0.4.2#AI-133.970939, eap:true,6,main] 1198871553

9:41:13 PM编译在12秒内成功完成

清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.conversation" >

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.conversation.splash"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:theme="@android:style/Theme.NoTitleBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

推荐答案

您可以执行以下操作:

private static final int SPLASH_TIME_OUT = 2000;
private static final Handler mHandler = new Handler();

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

    mHandler.postDelayed(new Runnable() {

        @Override
        public void run() {

                startActivity(new Intent(getApplicationContext(), YourActivity.class)); 
                finish();   
        }
    }, SPLASH_TIME_OUT);    
}

此处activity_splash.xml是您的splash活动布局,YourActivity是您要转到的活动

这篇关于如何在Android中显示闪屏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在Android中显示闪屏?