android app加载启动图片需要新创建一个activity,在主activity先加载图片activity,展示过程结束后,显示主activity。具体流程如下:
一、创建图片activity的运行类
package com.smallart.myapplication; import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.media.MediaPlayer; import android.net.Uri; import android.os.Build; import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.os.Handler; import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; import android.view.WindowManager; import android.widget.Toast; import android.widget.ImageView; import com.nostra13.universalimageloader.core.ImageLoader; import java.lang.reflect.Method; public class HomeActivity extends AppCompatActivity { private ImageView mImageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); hideBottomUIMenu(this); setContentView(R.layout.activity_home); } }
二、在AndroidManisest.xml文件中,添加activity的注册
<application android:name="com.smallart.myapplication.Application" android:configChanges="orientation|keyboardHidden" android:allowBackup="true" android:icon="@mipmap/ic_app_icon" android:label="@string/app_name" android:roundIcon="@mipmap/ic_app_icon_round" android:largeHeap="true" android:supportsRtl="true" android:theme="@style/Theme.AppCompat.Light.NoActionBar"> <activity android:name=".MainActivity" android:screenOrientation="sensorLandscape" android:configChanges="orientation|keyboardHidden|screenSize"> </activity> <activity android:name=".HomeActivity" android:screenOrientation="sensorLandscape" android:configChanges="orientation|keyboardHidden|screenSize"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
三、显示图片,在HomeActivity.java中的onCreate中添加图片显示代码:
this.mImageView = ((ImageView)findViewById(R.id.img)); ImageLoader.getInstance().displayImage("drawable://bg_app_start.jpg", this.mImageView);
四、增加线程,5秒后切换activity,完整代码如下:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); hideBottomUIMenu(this); setContentView(R.layout.activity_home); this.mImageView = ((ImageView)findViewById(R.id.img)); ImageLoader.getInstance().displayImage("drawable://bg_app_start.jpg", this.mImageView); handler.sendEmptyMessageDelayed(0,5000); } private Handler handler = new Handler() { //Intent intent = new Intent(MainActivity.this, HomeActivity.class); @Override public void handleMessage(Message msg) { getHome(); super.handleMessage(msg); } }; public void getHome(){ Intent intent = new Intent(HomeActivity.this, MainActivity.class); startActivity(intent); overridePendingTransition(0, 0); finish(); }