Splash屏幕将不显示 [英] Splash Screen will not display
问题描述
Java:
package com.carouseldemo 。主要;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
public class Splash extends Activity {
private final int SPLASH_DISPLAY_LENGHT = 1000;
/ **首次创建活动时调用。 * /
@Override
public void onCreate(Bundle icicle){
super.onCreate(icicle);
setContentView(R.layout.splash);
/ *新处理程序启动菜单活动
*并在几秒钟后关闭此Splash-Screen * /
new Handler()。postDelayed(new Runnable() {
@Override
public void run(){
/ *创建一个将启动菜单活动的意图* /
意图mainIntent = new Intent(Splash.this, Menu.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
},SPLASH_DISPLAY_LENGHT);
}
}
XML:
<?xml version =1.0encoding =utf-8?>
< LinearLayout xmlns:android =http://schemas.android.com/apk/res/android
android:orientation =verticalandroid:layout_width =fill_parent
机器人:layout_height = FILL_PARENT >
< ImageView android:id =@ + id / splashscreenandroid:layout_width =wrap_content
android:layout_height =fill_parentandroid:src =@ drawable / cat
机器人:layout_gravity = 中心/>
< TextView android:layout_width =fill_parent
android:layout_height =wrap_contentandroid:text =Hello World,splash/>
< / LinearLayout>
清单:
code><?xml version =1.0encoding =utf-8?>
< manifest xmlns:android =http://schemas.android.com/apk/res/android
package =com.carouseldemo.main
android:versionCode = 1
android:versionName =1.0
>
< uses-sdk android:minSdkVersion =8android:targetSdkVersion =17android:screenOrientation =portrait/>
< application android:icon =@ drawable / buttononeandroid:label =@ string / app_name>
< activity android:name =。MainActivityandroid:label =@ string / app_nameandroid:screenOrientation =portraitandroid:configChanges =orientation | keyboardHidden>
< intent-filter>
< action android:name =android.intent.action.MAIN/>
< category android:name =android.intent.category.LAUNCHER/>
< / intent-filter>
< / activity>
< / application>
< / manifest>
MainActivity是清单文件中的启动器活动。所以,飞溅没有显示。
将启动器活动MainActivity更改为Splash,并为MainActivity更改另一个。
< application android:icon =@ drawable / buttononeandroid:label =@ string / app_name>
< activity android:name =。Splashandroid:label =@ string / app_nameandroid:screenOrientation =portraitandroid:configChanges =orientation | keyboardHidden>
< intent-filter>
< action android:name =android.intent.action.MAIN/>
< category android:name =android.intent.category.LAUNCHER/>
< / intent-filter>
< / activity>
< activity android:name =。MainActivity/>
< / application>
I am trying to implement a Splash Screen using this java and xml code. I created a separate java class from my main activity and placed the java code inside. I created an xml layout in my layout file and placed the xml code inside. However, my app appears normally without a splash screen. It never shows, but the app does not have any errors. Eclipse is not showing any errors either. What could be the cause to this? Thank you in advance. Here is the code.
Java:
package com.carouseldemo.main;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
public class Splash extends Activity {
private final int SPLASH_DISPLAY_LENGHT = 1000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splash);
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(Splash.this,Menu.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/splashscreen" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:src="@drawable/cat"
android:layout_gravity="center"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Hello World, splash"/>
</LinearLayout>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.carouseldemo.main"
android:versionCode="1"
android:versionName="1.0"
>
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" android:screenOrientation="portrait"/>
<application android:icon="@drawable/buttonone" android:label="@string/app_name">
<activity android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity is launcher activity in manifest file. So, splash is not showing.
Change the launcher activity MainActivity to Splash and write another for MainActivity.
<application android:icon="@drawable/buttonone" android:label="@string/app_name">
<activity android:name=".Splash" android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
</application>
这篇关于Splash屏幕将不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!