引导页设置
1.创建LauncherActivity .java类
package com.example.launcher;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import com.example.zhang.masterofsurveying.MainActivity;
import com.example.zhang.masterofsurveying.R;
public class LauncherActivity extends AppCompatActivity {
/**
* 1.延时2000ms
* 2.判断程序是否第一次运行
* 3.Activity全屏主题
*/
//闪屏业延时
private static final int HANDLER_SPLASH = 1001;
private Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
switch (msg.what) {
case HANDLER_SPLASH:
startActivity(new Intent(LauncherActivity.this, MainActivity.class));
finish();
break;
default:
break;
}
return false;
}
});
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_launcher);
initView();
}
//初始化View
private void initView() {
//延时2000ms
handler.sendEmptyMessageDelayed(HANDLER_SPLASH, 2000);
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onPause() {
super.onPause();
}
}
2.设置AndroidManifest.xml文件(引导页为起始页)
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!--启动页-->
<activity android:name="com.example.launcher.LauncherActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
</activity>
</application>
全屏样式设置
styles.xml使用如下样式
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
引导页面如下:
想要全屏显示,可以按照下面方式更改。
一 、创建导航activity的 xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:scaleType="centerCrop"
android:src="@mipmap/default_splash_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
二、 新增样式 在styles.xml
<!--全屏显示-->
<style name="AppTheme.FullScreen">
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
三、并且在androidManifest.xml中使在引导页下用该样式
<activity android:name=".activity.SplashActivity"
android:theme="@style/AppTheme.FullScreen">
运行结果: