自定义 启动页style
<style name="AppTheme.Launcher" parent="Theme.AppCompat.Light.NoActionBar">
<!-- 通过windowBackground可以设置背景色、背景图片、能解析出图片的XML文件等-->
<item name="android:windowBackground">@drawable/layer_launcher</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
drawable 自定义xml
<activity
android:name=".activity.StartActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.LauncherBg">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
activity使用 theme
<activity
android:name=".activity.StartActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.LauncherBg">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
启动页使用
public class StartActivity extends AppCompatActivity {
private Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
/*try {
Thread.sleep(1000); //线程休眠1s,使出现白屏时的效果更加明显
} catch (InterruptedException e) {
e.printStackTrace();
}*/
super.onCreate(savedInstanceState);
// 注意:此处将setContentView()方法注释掉
//setContentView(R.layout.activity_start);
handler.postDelayed(new Runnable() {
@Override
public void run() {
gotoLogin();
}
}, 2000);
}
/**
* 前往注册、登录主页
*/
private void gotoLogin() {
Intent intent = new Intent(StartActivity.this, LoginMainActivity.class);
startActivity(intent);
finish();
//取消界面跳转时的动画,使启动页的logo图片与注册、登录主页的logo图片完美衔接
overridePendingTransition(0, 0);
}
/**
* 屏蔽物理返回键
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
protected void onDestroy() {
if (handler != null) {
//If token is null, all callbacks and messages will be removed.
handler.removeCallbacksAndMessages(null);
}
super.onDestroy();
}
}