android studio3.1 添加闪屏页面(启动欢迎界面)(例子简单无BUG)

一卷旌收千骑虏,万全身出百重围。这篇文章主要讲述android studio3.1 添加闪屏页面(启动欢迎界面)(例子简单无BUG)相关的知识,希望能为你提供帮助。
截图
【android studio3.1 添加闪屏页面(启动欢迎界面)(例子简单无BUG)】

android studio3.1 添加闪屏页面(启动欢迎界面)(例子简单无BUG)

文章图片

启动页的
activity_splash.xml 

 
我用了一张图片自己添加吧
< ?xml version="1.0" encoding="utf-8"?> < RelativeLayout 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:id="@+id/activity_splash" tools:context=".SplashActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:background="@mipmap/diyi"> < /RelativeLayout>

manifest 定义

< ?xml version="1.0" encoding="utf-8"?> < manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.stdu"> < 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=".SplashActivity"> < intent-filter> < action android:name="android.intent.action.MAIN" /> < category android:name="android.intent.category.LAUNCHER" /> < /intent-filter> < /activity> < activity android:name=".MainActivity" /> < /application> < /manifest>

SplashActivity.javpackage com.stdu;

android studio3.1 添加闪屏页面(启动欢迎界面)(例子简单无BUG)

文章图片
android studio3.1 添加闪屏页面(启动欢迎界面)(例子简单无BUG)

文章图片
import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Window; import android.view.WindowManager; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.widget.RelativeLayout; public class SplashActivity extends AppCompatActivity {@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getSupportActionBar().hide(); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //AS下全屏隐藏标题栏代码 setContentView(R.layout.activity_splash); RelativeLayout laoutsplsh=findViewById(R.id.activity_splash); AlphaAnimation alphaAnimation =new AlphaAnimation(0.1f,1.0f); alphaAnimation.setDuration(2200); laoutsplsh.startAnimation(alphaAnimation); alphaAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) {}@Override public void onAnimationEnd(Animation animation) { Intent intent=new Intent(SplashActivity.this,MainActivity.class); //intent.setClass(getApplicationContext(),MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); //把那个MainActivity设置为栈底意思就是防止你按返回键的时候返回到哪个启动欢迎界面startActivity(intent); //载入主窗口 finish(); }@Override public void onAnimationRepeat(Animation animation) {} }); } }

View Code 
mainactivity.java
package com.stdu; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Window; public class MainActivity extends AppCompatActivity {@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); } }

安卓studio  遇到的问题 ,eclipse下取消标题栏的问题再安卓studio下无法取消 ,以及点击返回按钮  会返回到启动页面的问题  例子中都已经解决




 

    推荐阅读