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

  2、新建布局文件splash.xml

  < ?xml version="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中添加以下代码://http://www.my400800.cn

  setContentView(R.layout.splash);

  PackageManager 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改为默认启动,并且设置标题栏不可见。

  < ?xml version="1.0" encoding="utf-8"?>

< manifest xmlns:android="http://schemas.android.com/apk/res/android"

  package="com.lyt.android" android:versionCode="1" android:versionName="1.0">

  < application android:icon="@drawable/icon" android:label="@string/app_name">

  < activity android:name=".SplashActivity" android:label="@string/app_name"

  android:theme="@android:style/Theme.NoTitleBar">

  < intent-filter>

  < action android:name="android.intent.action.MAIN" />

  < category android:name="android.intent.category.LAUNCHER" />

  < /intent-filter>

  < /activity>

  < activity android:name=".SplashScreenActivity" android:label="@string/app_name" >

  < /activity>

  < /application>

  < uses-sdk android:minSdkVersion="8" />

  < /manifest>

  5、显示效果如下:

更多相关文章

  1. NPM 和webpack 的基础使用
  2. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  3. linux 下使用ndk-build编译android使用的c++静态库
  4. 解决 Android(安卓)N 7.0 上 报错:android.os.FileUriExposedExce
  5. 【Android】21.3 动画
  6. 如何将library项目打包成jar文件
  7. 《Android面试宝典》学习笔记(第五章:文件存储)
  8. IDA调试Android(安卓)so文件
  9. Android(安卓)studio使用SVN

随机推荐

  1. Android(安卓)图表--MPAndroidChart
  2. android 服务与多线程
  3. Service
  4. Android之Http请求基础
  5. android camera preview方向
  6. Android创建文件夹及文件并写入数据
  7. Android(安卓)杀掉自己进程的方法
  8. android按键 禁用
  9. Android(安卓)调用shell命令打印
  10. android 混淆打包后 Gson拿到的实体类转