参考:

创建Android启动界面:http://www.cnblogs.com/xiongbo/archive/2011/05/17/splash.html

android颜色color.xml设置:http://blog.163.com/gis_warrior/blog/static/19361717320128149423856/

android开发之提高应用启动速度_splash页面瞬时响应_避免APP启动闪白屏:http://blog.csdn.net/jason0539/article/details/45559507?utm_source=tuicool


#########################################################################3


新建项目SplashDemo,默认生成一个空Activity(MainActivity)

新建一个空Activity,命名为SplashActivity


修改res/values下的style.xml(如果没有则新建一个):

<resources>    <!-- Base application theme. -->    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">        <!-- Customize your theme here. -->    </style>    <style name="AppSplash" parent="android:Theme">        <item name="android:windowBackground">@drawable/draw</item>        <item name="android:windowNoTitle">true</item>    </style></resources>

添加一个自定义主体AppSplash,添加窗口背景图片以及设置窗口没有标题栏(这里为了避免app闪白屏)


同样在res/values目录下修改colors.xml(如果没有新建一个):

<?xml version="1.0" encoding="utf-8"?><resources>    <color name="white">#FFFFFF</color><!--白色 --></resources>

修改activity_splash.xml的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:background="@color/white"    >    <!-- android:scaleType是控制图片如何resized/moved来匹对ImageView的size    CENTER_INSIDE / centerInside  将图片的内容完整居中显示,通过按比例缩小或原来的size使得图片长/宽等于或小于View的长/宽 -->    <ImageView        android:scaleType="centerInside"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:id="@+id/wordpress_logo"        android:src="@drawable/draw2">    </ImageView>    <!-- android:typeface 字体风格 -->    <TextView        android:id="@+id/versionNumber"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textSize="20sp"        android:textStyle="bold"        android:layout_gravity="center_horizontal|bottom" /></LinearLayout>

修改SplashActivity.xml的代码如下:

import android.app.Activity;import android.content.Intent;import android.content.pm.PackageInfo;import android.content.pm.PackageManager;import android.graphics.PixelFormat;import android.os.Bundle;import android.os.Handler;import android.view.WindowManager;import android.widget.TextView;public class SplashActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_splash);        //Display the current version number        PackageManager pm = getPackageManager();        try {            PackageInfo pi = pm.getPackageInfo("com.zj.splashdemo", 0);            TextView versionNumber = (TextView) findViewById(R.id.versionNumber);            versionNumber.setText("Version " + pi.versionName);        } catch (PackageManager.NameNotFoundException e) {            e.printStackTrace();        }        //splash_view=(ImageView)findViewById(R.id.splash_view);        new Handler().postDelayed(new Runnable() {            public void run() {                /* Create an Intent that will start the Main WordPress Activity. */                Intent mainIntent = new Intent(SplashActivity.this, MainActivity.class);                startActivity(mainIntent);                finish();            }        }, 2900); //2900 for release    }}

在SplashActivity活动中显示图片(居中)和版本号(下部)


最后修改AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.zj.splashdemo" >    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name=".MainActivity"            android:label="@string/app_name" >        </activity>        <activity            android:name=".SplashActivity"            android:label="@string/app_name"            android:theme="@style/AppSplash"            >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>


这样运行程序即可


更多相关文章

  1. Android(安卓)学习记录-ImageView显示格式
  2. Android中通过Intent 调用图片、视频、音频、录音、拍照
  3. Android(安卓)屏幕适配
  4. Android(安卓)深入解析selector
  5. Android(安卓)深入解析selector
  6. Android(安卓)8.1 关机充电动画(三)Android模式
  7. 8 Android平台开发-WIFI 驱动移植 -- 详细
  8. Android加载/处理超大图片神器!
  9. android 永远锁屏解决方法

随机推荐

  1. FAQ_05_查看 android 设备 ip
  2. android studio 打包 so 库
  3. Android SDK和最新ADT下载地址 + 环境搭
  4. Mono for Android—初体验之“电话拨号器
  5. 关于Android(安卓)Pie(Android(安卓)9.0),你
  6. 全屏、小屏、横屏、竖屏的切换
  7. android listview的divider分割线的宽度
  8. Android Drawable缓存
  9. android之实现ProgressBar进度条组件
  10. Android 隐藏ActionBar