我有一个关于在我的应用中加载第一个Activity的问题。在加载之前,应用会显示以下屏幕:https://www.dropbox.com/s/r33n3u3xfmth345/Screenshot_2013-08-16-12-02-08.png,我想要的是直接加载我的活动。
我会提到我m using SherlockActivity, and I already tried setting the Theme both in Manifest or programatically in onCreate() of my Activity, with same result (pre-load
在该屏幕上持续2-3秒,然后加载我的活动)。
有什么想法吗?
答案 0 :(得分:0)
您必须使用启动画面活动,之后您必须从该启动画面活动开始自己的活动。
以下是 splashActivity。
的代码public class SplashActivity extends Activity {
private int splashTime = 3000;
private Thread thread;
private ProgressBar mSpinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
mSpinner = (ProgressBar) findViewById(R.id.Splash_ProgressBar);
mSpinner.setIndeterminate(true);
thread = new Thread(runable);
thread.start();
}
public Runnable runable = new Runnable() {
public void run() {
try {
Thread.sleep(splashTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
startActivity(new Intent(SplashActivity.this,YourActivityName.class));
finish();
} catch (Exception e) {
// TODO: handle exception
}
}
};
}
以下是 activity_spalsh.xml 文件的代码.....
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#48AD83"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text=" your app name "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#A52A2A" />
<ProgressBar
android:id="@+id/Splash_ProgressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerInParent="true"
android:layout_marginTop="5dp" />
</RelativeLayout>