大部分Android App启动过程中,都会设置一个背景图片,直到App加载成功,图片消失。因此,这也是做Android App的基本技能之一。这个过程实现起来并不难。
总共需要以下内容:2个Activity,一张背景图,2个xml配置文件,String.xml,AndroidManifest写入配置信息。
1 准备一张背景图图片,命名为load,自己选择图片格式。放在drawable目录下
2 创建Load页面 LoadActivity.java及相关布局文件load.xml
LoadActivity.java
[java] view
plaincopy
packagecom.timothy.load;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.content.Intent;
importandroid.graphics.PixelFormat;
importandroid.os.Handler;
importandroid.view.WindowManager;
publicclassLoadActivityextendsActivity {
//time for picture display
privatestaticfinalintLOAD_DISPLAY_TIME =1500;
/** Called when the activity is first created. */
@Override
publicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.RGBA_8888);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
setContentView(R.layout.load);
newHandler().postDelayed(newRunnable() {
publicvoidrun() {
//Go to main activity, and finish load activity
Intent mainIntent = newIntent(LoadActivity.this, MainActivity.class);
LoadActivity.this.startActivity(mainIntent);
LoadActivity.this.finish();
}
}, LOAD_DISPLAY_TIME);
}
}
load.xml
[html] view
plaincopy
android:orientation="vertical"
android:gravity="center|center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/load">
3 创建主页面 MainActivity.java及相关布局文件main.xml
MainActivity.java
[java] view
plaincopy
packagecom.timothy.load;
importandroid.app.Activity;
importandroid.os.Bundle;
publicclassMainActivityextendsActivity {
/** Called when the activity is first created. */
@Override
publicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
main.xml
[html] view
plaincopy
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
4 配置strings.xml
[html] view
plaincopy
Hello, this is a demo to picture before app start
LoadPictureDemo
@drawable/load
true
true
@null
5 配置AndroidManifest.xml
[html] view
plaincopy
package="com.timothy.load"
android:versionCode="1"
android:versionName="1.0">
android:configChanges="orientation|keyboardHidden"
android:theme="@style/MyTheme.NoTitleBar.CustomBackground">
6 OK, 编译运行
启动过程中:
完成启动: