解決Android啟動顯示空白介面的問題,自定義進入軟體前的背景圖片
阿新 • • 發佈:2018-12-18
1.新建xml檔案 設定其背景圖片 android:background="@mipmap/initmap"
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@mipmap/initmap" tools:context=".SplashActivity"> </LinearLayout>
2.建立對應的Java檔案
package com.example.testmap; import android.app.Activity; import android.content.Intent; import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.WindowManager; public class SplashActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_splash); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { goLoginActivity(); } }, 1000);//介面顯示時間 } private void goLoginActivity(){ Intent intent = new Intent(this, MainActivity.class); this.startActivity(intent); this.finish(); } }
Intent intent = new Intent(this, MainActivity.class); MainActivity.class為你1s後將要進入的介面
3.然後再設定軟體初始顯示介面
<activity android:name=".SplashActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>