Android实现闪屏页效果

作者:luckyliuqs 时间:2022-01-17 01:21:47 

本文实例为大家分享了Android实现闪屏页效果的具体代码,供大家参考,具体内容如下

1.效果图

Android实现闪屏页效果

2.闪屏页逻辑及布局

2.1 activity_splash.xml


<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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">

<ImageView
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:src="@drawable/splash"
 android:scaleType="centerCrop"/>

<Button
 android:id="@+id/splash_btn_skip"
 android:layout_width="45dp"
 android:layout_height="32dp"
 android:text="跳过"
 android:textStyle="bold"
 android:textColor="#fff"
 android:background="#30000000"
 android:layout_gravity="right"
 android:layout_marginTop="30dp"
 android:layout_marginRight="30dp"/>
</FrameLayout>

2.2 SplashActivity.java

通过Handler实现


public class SplashActivity extends AppCompatActivity {
//跳过按钮
private Button btnSkip;
private Handler handler = new Handler();
private Runnable runnableToLogin = new Runnable() {
 @Override
 public void run() {
  toLoginActivity();
 }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_splash);

initView();
 initEvent();

//延迟4秒
 handler.postDelayed(runnableToLogin,4000);

}

//初始化组件
public void initView(){
 btnSkip = findViewById(R.id.splash_btn_skip);
}

//监听事件
public void initEvent(){
 btnSkip.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
   //防止LoginActivity被打开两次
   handler.removeCallbacks(runnableToLogin);
   toLoginActivity();
  }
 });
}

/**
 * 跳转到登录界面
 */
private void toLoginActivity(){
 Intent intent = new Intent(this,LoginActivity.class);
 startActivity(intent);
 finish();
}

@Override
protected void onDestroy() {
 super.onDestroy();
 //防止内存泄漏
 handler.removeCallbacks(runnableToLogin);
}
}

3.设置主题样式

3.1 style.xml中


<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
 <!-- Customize your theme here. -->
 <item name="colorPrimary">@color/colorPrimary</item>
 <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
 <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme_FullScreen" parent="AppTheme">
 <item name="android:windowFullscreen">true</item>
</style>
</resources>

3.2 AndroidManifest.xml中


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myrestaurant">

<uses-permission android:name="android.permission.INTERNET" />

<application
 android:allowBackup="true"
 android:icon="@mipmap/ic_launcher"
 android:label="@string/app_name"
 android:roundIcon="@mipmap/ic_launcher_round"
 android:supportsRtl="true"
 android:theme="@style/AppTheme">
 <activity android:name=".LoginActivity"></activity>
 <activity android:name=".SplashActivity"
  android:theme="@style/AppTheme_FullScreen">
  <intent-filter>
   <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
 </activity>
</application>

</manifest>

来源:https://blog.csdn.net/qq_35507234/article/details/88046858

标签:Android,闪屏页
0
投稿

猜你喜欢

  • Unity快速生成常用文件夹的方法

    2023-12-11 20:37:43
  • Spring中的后置处理器BeanPostProcessor详解

    2023-02-24 00:50:03
  • c# 通过代码开启或关闭防火墙

    2021-12-11 19:53:20
  • 浅谈Java线程Thread之interrupt中断解析

    2023-07-19 09:25:11
  • InputStream数据结构示例解析

    2022-06-12 20:11:53
  • 什么是Java自旋锁

    2022-09-22 22:10:55
  • SpringBoot如何使用RateLimiter通过AOP方式进行限流

    2023-09-16 18:18:44
  • 详解如何在Android studio中更新sdk版本和build-tools版本

    2023-11-18 04:36:15
  • Flutter之Timer实现短信验证码获取60s倒计时功能的代码

    2023-07-20 20:00:30
  • linux下idea、pycharm等输入中文拼音时满3个字母后无法继续拼音输入的问题

    2022-03-03 20:49:19
  • JDK源码分析之String、StringBuilder和StringBuffer

    2022-01-23 00:10:20
  • Android编程中Tween动画和Frame动画实例分析

    2023-12-03 06:31:56
  • Java调用Shell命令和脚本的实现

    2023-11-29 00:59:09
  • java split()使用方法解析

    2023-10-18 01:59:23
  • Android Support Annotations资料整理

    2021-09-21 13:39:33
  • java8 stream的多字段排序实现(踩坑)

    2023-10-22 11:06:31
  • java二维数组指定不同长度实例方法

    2021-07-13 06:02:09
  • Flutter 容器盒子模型的使用示例

    2023-06-18 18:47:43
  • Android简单实现文件下载

    2023-08-28 06:33:17
  • 如何使用Jenkins编译并打包SpringCloud微服务目录

    2021-09-25 07:07:01
  • asp之家 软件编程 m.aspxhome.com