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

2、新建布局文件splash.xml

<? xmlversion="1.0"encoding="utf-8" ?>
< LinearLayout xmlns:android ="http://schemas.android.com/apk/res/android"
android:layout_width
="fill_parent" android:layout_height ="fill_parent"
android:gravity
="bottom|center" android:orientation ="vertical"
android:background
="@drawable/splash" >
< TextView android:text ="@+id/TextView01" android:layout_width ="wrap_content"
android:layout_height
="wrap_content" android:layout_marginTop ="20dip"
android:typeface
="sans" android:shadowDx ="0" android:shadowDy ="2"
android:shadowRadius
="1" android:shadowColor ="#FFFFFF"
android:textColor
="#444444" android:textSize ="20dip" android:id ="@+id/versionNumber"
android:gravity
="bottom" >
</ TextView >
</ LinearLayout >

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

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

setContentView(R.layout.splash);

PackageManagerpm = getPackageManager();
try {
PackageInfopi
= pm.getPackageInfo( " com.lyt.android " , 0 );
TextViewversionNumber
= (TextView)findViewById(R.id.versionNumber);
versionNumber.setText(
" Version " + pi.versionName);
}
catch (NameNotFoundExceptione){
e.printStackTrace();
}

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

@Override
public void run(){
Intentintent
= new Intent(SplashActivity. this ,SplashScreenActivity. class );
startActivity(intent);
SplashActivity.
this .finish();
}

},
2500 );

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

<?xmlversion="1.0"encoding="utf-8"?>

< manifestxmlns:android = " http://schemas.android.com/apk/res/android "
package = " com.lyt.android " android:versionCode = " 1 " android:versionName = " 1.0 " >
< applicationandroid:icon = " @drawable/icon " android:label = " @string/app_name " >

< activityandroid:name = " .SplashActivity " android:label = " @string/app_name "
android:theme
= " @android:style/Theme.NoTitleBar " >
< intent - filter >
< actionandroid:name = " android.intent.action.MAIN " />
< categoryandroid:name = " android.intent.category.LAUNCHER " />
</ intent - filter >
</ activity >
< activityandroid:name = " .SplashScreenActivity " android:label = " @string/app_name " >
</ activity >
</ application >
< uses - sdkandroid:minSdkVersion = " 8 " />

</ manifest >

5、显示效果如下:

更多相关文章

  1. NPM 和webpack 的基础使用
  2. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  3. Android(安卓)Adapter详解
  4. Android(安卓)Studio启动时报错 “ Plugin "XXX" was not loaded
  5. android studio3.6.3编译Telegram android 1482 问题小记(nebula
  6. Android(安卓)HttpClient post MultipartEntity - Android(安卓)
  7. debug.keystore过期问题
  8. Android在开机时自动启动一个应用程序
  9. Android之常用文件路径

随机推荐

  1. php实现顺序线性表
  2. Kubernetes 如果是个水族馆
  3. 自学系列 | 就谈自我管理!
  4. 智慧城市信息安全探讨
  5. 1-22
  6. 动画:面试必刷之二叉树的子结构
  7. 详解 centos7设置nfs文件共享 实操记
  8. 2020 总结 | VoltDB的亮点,你了解多少?
  9. 自学系列 | 俺今天就谈兴趣!
  10. 自学第五十五天