android - Android Splash Screen App Icon加载后不会消失 - React Native
问题描述
我在这里遵循了本教程,它确实有效,因为它在我的应用程序上添加了启动屏幕应用程序徽标。
基本上在我的AndroidManifest.xml
文件中,我有 ff 代码:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.coupalreactnative">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/SplashTheme"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
然后在我的res/drawable/splash_screen.xml
文件上:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/white"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/books_splash"/>
</item>
</layer-list>
当我运行该应用程序时,它基本上可以工作,但是即使主屏幕已经加载,应用程序徽标也不会在背景上消失。
我是 React Native 的初学者,有什么解决方法吗?我如何解决它?
解决方案
我已经这样做了(在 Kotlin 中,但我认为在 java 中是一样的):
- 创建一个 SplashScreen 活动
- 设置 SplashScreen 的布局(使用 ImageView)
- 使用 viewBinding(在 gradle 中设置:BuildFeatures { viewBinding = true }
- 复制可绘制文件夹中的徽标/图像并将其源到 ImageView
- 创建动画 XML 文件
- 使用绑定、layoutInflater 加载 SplashScreen 布局
- 创建和实现动画功能(在 AnimationEnd 上)
- 在 onAnimationEnd 函数中,我设置了 2.5 秒的延迟,然后关闭 SplashScreen 并转到 MainActivity。
- 确保您将 MAIN 和 LAUNCHER 的 INTENT 设置为 SplashScreenActivity(在 AndroidManifest 中)
我的安卓清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.uwbeinternational.weatherapp">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:networkSecurityConfig="@xml/network_security_config">
<activity
android:name=".SplashScreenActivity"
android:exported="true"
android:theme="@style/Theme.UwBeWeatherApp.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
</activity>
</application>
</manifest>
我的动画 XML 文件(在新文件夹/包“anim”下):
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<!--<translate
android:duration="2000"
android:fromXDelta="0%p"
android:fromYDelta="0%p"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toXDelta="0%p"
android:toYDelta="50%p"
/>-->
<alpha
android:duration="2000"
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator">
</alpha>
</set>
我的 SplashScreen 活动:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//SplashScreen - UwBe Logo Anzeigen und einblenden lasssen
val splashBinding: ActivitySplashScreenBinding = ActivitySplashScreenBinding.inflate(layoutInflater)
setContentView(splashBinding.root)
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.insetsController?.hide(WindowInsets.Type.statusBars())
} else {
@Suppress("DEPRECATION")
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
}
val splashAnimation = AnimationUtils.loadAnimation(this, R.anim.anim_splash)
splashBinding.ivAppLogo.animation = splashAnimation
splashAnimation.setAnimationListener(object: Animation.AnimationListener{
override fun onAnimationStart(animation: Animation?) {
//
}
override fun onAnimationEnd(animation: Animation?) {
Handler(Looper.getMainLooper()).postDelayed({
startActivity(Intent(this@SplashScreenActivity, MainActivity::class.java))
finish()
}, 1500)
}
override fun onAnimationRepeat(animation: Animation?) {
//
}
})
推荐阅读
- java - 如何使用 IDEA 的 GUI 表生成表?
- woocommerce - WooCommerce - 以编程方式更新产品 tax_class
- javascript - 如何防止用户编辑电子源文件?
- r - 我无法使用 ggplot2 在 R 中打印条形图
- python - 从文件中读取行的“for”循环不起作用
- database - 如何查询 DynamoDB 电影示例数据库以按类型检索电影
- algorithm - 如何构建 S3 资源以组合资源下载
- ansible - 由于意外的 HTTP POST 响应代码,未能创建记录。预期 201,得到 401
- hl7-fhir - 调用 FHIR API 时如何通过 X509 证书?
- r - 在条形图中使用 ggplot 中的 coord_*() 函数