【发布时间】:2013-02-06 05:10:39
【问题描述】:
我正在尝试使用此 java 和 xml 代码实现启动画面。我从我的主要活动中创建了一个单独的 java 类,并将 java 代码放入其中。我在布局文件中创建了一个 xml 布局,并将 xml 代码放入其中。但是,我的应用程序正常显示,没有启动画面。它从不显示,但应用程序没有任何错误。 Eclipse 也没有显示任何错误。这可能是什么原因?先感谢您。这是代码。
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>
清单:
<?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>
【问题讨论】:
-
闪屏显示时间是1秒,能不能保持4-5秒左右再检查一下。
-
我将时间增加到 10 秒。它会显示大约一秒钟的黑屏并打开应用程序。
-
Manifest File 怎么样??您是否已将启动画面注册为 Launcher Activity..您能在此处发布您的 Manifest 文件吗?
-
您的 java 代码没问题,不需要更改。这只是个小问题。
-
我已经用清单文件更新了我的问题。
标签: java android eclipse screen splash-screen