为了让app的逼格更高 为了让app的界面更人性化,并且让app在刚刚启动数据还没加载出来时不至于一片白屏太难看以至于吓跑用户,尝试增加一个启动页面。
首先建立一个新的empty Activity,给它命名为LaunchActivity,这时候多出来两个文件
java文件LaunchActivity和布局文件activity_launch.xml
编辑布局文件,其实就是在里边塞一个图片
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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" tools:context=".LaunchActivity"> <!--该xml定义了启动界面,比如塞进去一个图片--> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="fitXY" android:src="@drawable/start_loading" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout>
编辑LaunchActivity,这个Activity主要干了两件事:显示一个图片,然后在两秒之后进入下一个即MainActivity
package com.example.windelves; import androidx.appcompat.app.AppCompatActivity; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; //该activity为初始启动页,app启动时应当第一个启动该Activity, //在该activity完成一些乱七八糟的麻烦任务,并且显示应用程序启动页以显得高逼格 public class LaunchActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_launch); Integer time = 2000; //设置等待时间,单位为毫秒 Handler handler = new Handler(); //当计时结束时,跳转至主界面 handler.postDelayed(new Runnable() { @Override public void run() { startActivity(new Intent(LaunchActivity.this, MainActivity.class)); LaunchActivity.this.finish(); } }, time); } }
接下来编辑注册表单AndroidManifest.xml,
将这些代码
<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>
拖进LaunchActivity里,即
<!--LaunchActivity被设置为了启动activity--> <activity android:name=".LaunchActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
app启动时将首先启动LaunchActivity。
原文地址:http://www.cnblogs.com/soaring27221/p/16814573.html
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,请务用于商业用途!
3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员!
8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载
声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性