我
我是 React Native 的初學者,對此有什么解決方法嗎?我如何解決它?
uj5u.com熱心網友回復:
您只有一項活動。我會創建一個新的活動,將影像顯示為 SplashScreen。您可以將其加載為 Launcher/Main(在 Manifest 中設定 Intent)并在 2 秒后轉到 MainActivity。如果您需要幫助,請隨時給我寫信。
uj5u.com熱心網友回復:
如果我理解正確,它甚至在您遵循的教程中提到:
- 不要忘記為您的根視圖設定背景。這個需要是因為啟影片面總是在你的 js 視圖下。所以如果沒有設定背景,它將是可見的。
因此,在您的 js 代碼中嘗試在頂級視圖上設定背景顏色。
編輯:
因此,例如添加包含flex:1的樣式容器以拉伸全屏和您想要的背景顏色,在本例中為“白色”:
export default function App() {
return (
<View style={styles.container}>
<Text style={styles.title}>
Home
</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
},
title: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
});
uj5u.com熱心網友回復:
我已經這樣做了(在 Kotlin 中,但我認為在 Java 中也是如此):
- 創建啟影片面活動
- 設定 SplashScreen 的布局(使用 ImageView)
- 使用 viewBinding(在 gradle 中設定:BuildFeatures { viewBinding = true }
- 復制 drawablefolder 中的 Logo/Image 并在 ImageView 上獲取它
- 創建影片 XML 檔案
- 使用系結、layoutInflater 加載 SplashScreen 布局
- 創建并實作影片功能(在 AnimationEnd 上)
- 在 onAnimationEnd 函式中,我將延遲設定為 2.5 秒,然后關閉 SplashScreen 并轉到 MainActivity。
- 確保將 MAIN 和 LAUNCHER 的 INTENT 設定為 SplashScreenActivity(在 AndroidManifest 中)
我的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>
我的啟影片面活動:
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?) {
//
}
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/338112.html
