该问题的解决方法是在styles.xml文件中添加如下代码:
- 50
这将使启动屏幕动画快速消失,从而避免额外的空白空间出现。如果你的应用使用了Kotlin,则可以使用如下代码:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportActionBar?.hide()
setTheme(R.style.Theme_MyApp_SplashScreen)
setContentView(R.layout.activity_main)
// Remove the splash screen after exiting animation
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
Handler(Looper.getMainLooper()).postDelayed({
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_VISIBLE
}, resources.getInteger(R.integer.splash_duration).toLong())
// Set navigation graph
val navController = findNavController(R.id.fragment_nav_host)
findViewById(R.id.bottom_nav_view)
.setupWithNavController(navController)
}
override fun onResume() {
super.onResume()
supportActionBar?.hide()
}
}
这里通过设置系统UI可见性标志来消除了额外的空白,此外还使用了Handler来延迟一段时间后隐藏系统UI。