android入门教程创建启动界面

android入门教程创建启动界面
android入门教程创建启动界面

android入门教程创建启动界面

1、制作一张启动图片splash.png,放置在res->drawable-hdpi文件夹中。

2、新建布局文件splash.xml

这里我们把上一步制作的图片作为启动界面的背景图,然后在界面底部显示当前程序的版本号。

3、新建SplashActivity,在Oncreate中添加以下代码:

setContentView(https://www.360docs.net/doc/9d14417871.html,yout.splash);

pm = getPackageManager();

try {

PackageInfo pi = pm.getPackageInfo("com.lyt.android", 0);

TextView versionNumber = (TextView) findViewById(R.id.versionNumber);

versionNumber.setText("Version " + pi.versionName);

} catch (NameNotFoundException e) {

e.printStackTrace();

}

new Handler().postDelayed(new Runnable(){

@Override

public void run() {

Intent intent = new Intent(SplashActivity.this,SplashScreenActivity.class);

startActivity(intent);

SplashActivity.this.finish();

}

}, 2500);

4、修改Manifest文件,将启动界面Activity改为默认启动,并且设置标题栏不可见。

5、显示效果如下:

相关主题
相关文档
最新文档