欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android实现欢迎页快速启动的方法

程序员文章站 2023-12-18 17:27:22
android 欢迎页快速启动 大家应该都知道,在默认情况下,android app在点击app logo到app完全启动这之间会有一段时间空白期。那么如何做到在用户...

android 欢迎页快速启动

大家应该都知道,在默认情况下,android app在点击app logo到app完全启动这之间会有一段时间空白期。那么如何做到在用户点击logo图标之后立即打开app的界面而不是一段白屏或黑屏呢?

设置xml

在drawable下建立welcome.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 <!--背景色-->
 <item android:drawable="@color/white"/>
 <item>
  <!--图片-->
  <bitmap
   android:gravity="center"
   android:src="@mipmap/welcome_page"/>
 </item>
</layer-list>

设置style

<!-- base application theme. -->
 <style name="apptheme" parent="theme.appcompat.light.darkactionbar">
  <!-- customize your theme here. -->
 </style>
 <style name="welcomethem" parent="apptheme">
  <item name="android:windowbackground">@drawable/welcome</item>
 </style>

清单文件中配置style

<!-- 欢迎页 -->
  <activity
   android:name=".ui.welcomeactivity"
   android:windowsoftinputmode="adjustnothing" android:theme="@style/welcomethem">
   <intent-filter>
    <action android:name="android.intent.action.main"/>
    <category android:name="android.intent.category.launcher"/>
   </intent-filter>
  </activity>

activity中不需要设置setcontentview()

public class welcomeactivity extends appcompatactivity {
 @override
 protected void oncreate(bundle savedinstancestate) {
  super.oncreate(savedinstancestate);
  intent intent = new intent(this, mainactivity.class);
  startactivity(intent);
  finish();
 }
}

不需要为你的splashactivity设置一个视图,这个视图来自于主题,在主题中为你的splashactivity设置ui就足够了。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对的支持。

上一篇:

下一篇: