首页 > 其他分享 >Android 增加一个应用启动界面

Android 增加一个应用启动界面

时间:2022-10-21 19:34:54浏览次数:73  
标签:界面 启动 app activity LaunchActivity Activity import Android

为了让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。

标签:界面,启动,app,activity,LaunchActivity,Activity,import,Android
From: https://www.cnblogs.com/soaring27221/p/16814573.html

相关文章

  • Android 软键盘删除键触发问题分享
    本文解决的问题:Android输入法软键盘删除键点击多次,只触发一次删除事件本文示例代码地址:Android软键盘删除键触发示例代码背景笔者维护的app功能中,有个图文编辑器,由......
  • #Android studio 微信页面制作(二)
    今天继续用Androidstudio实现微信页面的制作首先打开项目看看之前的进展。这里我在第一次制作的基础上,使用recycleview等控件对联系录页面进行了新的UI设计布局。本次......
  • android有声电子书新版本1.61发布
    有声电子书(适用于Android1.5及以上版本)软件支持格式为txt,umd,jpg文字及漫画书的阅读,提供用户搜索SD卡中所有图书。特别加入了文本直接转换成语音的有声阅读功能。......
  • Android软件中嵌入地图之一:Sogou地图
          在App中加入地图功能真是让人揪结,Google地图功能强大,但是有些国内的手机厂商去掉了手机系统中Google地图的相关库,所以这类机型将无法安装调用了Google地图的软......
  • Android 代码库
    -​​安卓巴士​​-​​Arsenal​​-​​AndroidLibraries​​-​​Gems​​-​​Appance​​-​​Devstore​​-​​android-nice-repo​​-​​apkdemo​......
  • android异步任务 访问网络 加载图片 解决方案大集合
    1.Handler+Thread异步执行任务在UI线程中开启子线程,使用Handler发消息,通知主线程更新UI​直接在UI线程中开启子线程来更新TextView显示的内容,运行程序我们会发现,如下......
  • Android 学习导航
    -​​android-open-project(Trinea)​​-​​android-open-project-demo(开源项目Demo)​​-​​MaterialDesign(Material案例大全)​​-​​awesome-android-ui​​......
  • 设置开机启动软件
    1、打开我的电脑,在地址栏中输入C:\ProgramData\Microsoft\Windows\StartMenu\Programs\StartUp,回车,进入该文件夹,这是启动项所在文件夹。2、将需要添加开机启动的文件或......
  • 解决matlab2022a启动提示
    linux下安装完matlab2022a后,之后,每次启动都会有:MESA-LOADER:failedtoopeniris:/usr/local/MATLAB/R2022a/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6:version......
  • android Activity的启动流程源码分析
    ActivityThread在handlebindapplication中执行完Application的初始化之后会继续进入到消息循环中接收AMS(activitymanagerservice)启动activity的消息。AMS首先会发送启动......