简单实现Android应用的启动页
作者:糖心荷包蛋° 时间:2022-04-15 14:23:45
前言:
平时打开手机的应用时,会跳出来3秒钟的广告后,再进入应用。今天我们就来简单实现一下引导页的功能。
1、首先,新建一个activity页面,命名:SplashActivity
在 activity_splash.xml中添加启动页内容,我这里添加了一个图片(图片放在drawable文件下),代码如下:
<?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"
android:background="@drawable/zhz"
tools:context=".SplashActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/zhz"></ImageView>
</androidx.constraintlayout.widget.ConstraintLayout>
在java文件中,将启动页状态栏和标题栏隐藏,并设置启动页显示时间为3秒。
SplashActivity.java代码如下:
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//隐藏状态栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
//隐藏标题栏
getSupportActionBar().hide();
setContentView(R.layout.activity_splash);
//创建子线程
Thread mThread=new Thread(){
@Override
public void run() {
super.run();
try {
sleep(3000);//使程序休眠3秒
Intent intent=new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
finish();
}catch (Exception e){
e.printStackTrace();
}
}
};
mThread.start();//启动线程
}
}
2、在AndroidManifest.xml文件中,设置启动页为.SplashActivity,代码如下:
<activity android:name=".StartActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
3、我这里将应用图标改为自己的图片了,你们根据自己需要(不改也行的),代码如下:
这样就完成了所有步骤了,运行一下试试吧!
来源:https://blog.csdn.net/Waterme10n/article/details/124198398
标签:Android,应用,启动页
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#实现XML文件操作详解
2023-07-16 12:36:52
![](https://img.aspxhome.com/file/2023/0/67050_0s.png)
Android中使用定时器的三种方法
2022-06-04 00:16:20
![](https://img.aspxhome.com/file/2023/8/137158_0s.gif)
SpringBoot之@Value获取application.properties配置无效的解决
2023-09-15 22:37:55
android 调用系统的照相机和图库实例详解
2022-01-02 11:46:47
Android自定义View之绘制圆形头像功能
2022-09-27 19:24:29
![](https://img.aspxhome.com/file/2023/5/92575_0s.png)
java安全编码指南之:表达式规则说明
2021-06-01 17:48:44
Android实现图片点击放大
2023-03-19 17:40:59
C#设置MDI子窗体只能弹出一个的方法
2022-03-19 23:40:11
![](https://img.aspxhome.com/file/2023/3/98273_0s.png)
C# 通过NI-VISA操作Tektronix TBS 2000B系列示波器的实现步骤
2023-11-02 01:44:38
![](https://img.aspxhome.com/file/2023/0/84460_0s.png)
Java新特性之Nashorn_动力节点Java学院整理
2022-07-31 17:18:13
![](https://img.aspxhome.com/file/2023/2/62822_0s.png)
解析在C#中接口和类的异同
2022-04-10 13:02:07
![](https://img.aspxhome.com/file/2023/6/68096_0s.png)
C#导出网站功能实例代码讲解
2023-09-15 03:15:36
Java之 TreeSet的详细使用说明
2021-08-22 14:52:22
![](https://img.aspxhome.com/file/2023/8/77078_0s.jpg)
Windows实现Flutter环境搭建及配置这一篇就够了
2023-07-03 22:49:30
![](https://img.aspxhome.com/file/2023/5/108275_0s.jpg)
Android图片缓存之Bitmap详解(一)
2021-10-24 15:45:08
![](https://img.aspxhome.com/file/2023/2/130462_0s.jpg)
C语言实现2D赛车游戏的示例代码
2022-04-03 05:57:33
![](https://img.aspxhome.com/file/2023/4/117794_0s.jpg)
android开发去除标题栏的方法
2021-06-30 19:11:29
![](https://img.aspxhome.com/file/2023/0/109170_0s.png)
Android setButtonDrawable()的兼容问题解决办法
2021-12-11 04:33:52
JAVA8 十大新特性详解
2023-07-02 10:03:27
代码详解Java猴子选王问题(约瑟夫环)
2023-09-16 07:33:43