android 启动图片显示消息数量,Android启动过程中背景图片显示

大部分Android App启动过程中,都会设置一个背景图片,直到App加载成功,图片消失。因此,这也是做Android App的基本技能之一。这个过程实现起来并不难。

总共需要以下内容:2个Activity,一张背景图,2个xml配置文件,String.xml,AndroidManifest写入配置信息。

7547138

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, 编译运行

启动过程中:

7547138

完成启动:

7547138

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值