赞
踩
流程如下:
找到一张图片,粘贴复制到项目下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" tools:context=".WelcomeActivity"> <ImageView android:id="@+id/imageView" android:layout_width="0dp" android:layout_height="0dp" android:scaleType="centerCrop" android:scaleX="1.2" android:scaleY="1.2" android:src="@drawable/welcome_image" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout>
package com.example.gca import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.View import androidx.core.view.ViewCompat import androidx.core.view.ViewPropertyAnimatorListener import kotlinx.android.synthetic.main.activity_welcome.* class WelcomeActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_welcome) //设置图片动画 ViewCompat.animate(imageView).apply { //缩放,变成1.0倍 scaleX(1.0f) scaleY(1.0f) //动画时常1秒 duration = 1000 //动画监听 setListener(object : ViewPropertyAnimatorListener { override fun onAnimationEnd(view: View?) { //动画结束 //进入主界面,并结束掉该页面 startActivity(Intent(this@WelcomeActivity, MainActivity::class.java)) finish() } override fun onAnimationCancel(view: View?) { } override fun onAnimationStart(view: View?) { } }) } } }
这里要做的就是新建一个style(全屏)给WelcomeActivity,同时让WelcomeActivity成为启动界面
在res/values/styles.xml文件内新建一个style(添加以下代码)
<style name="AppTheme.FullScreen"> //style名字
<item name="windowNoTitle">true</item> //不显示标题
<item name="android:windowFullscreen">true</item> //全屏
</style>
完成如下:(添加之后的样子)
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- 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">
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>
style(全屏)给WelcomeActivity,同时让WelcomeActivity成为启动界面,修改前:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:dist="http://schemas.android.com/apk/distribution" package="com.example.gca"> <dist:module dist:instant="true" /> <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=".WelcomeActivity"></activity> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
修改后:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:dist="http://schemas.android.com/apk/distribution" package="com.example.gca"> <dist:module dist:instant="true" /> <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=".MainActivity"></activity> <activity android:name=".WelcomeActivity" 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>
如果觉得有用,点个赞吧
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。