如何删除启动画面之前出现的白屏?
How can I remove white screen which appear before splash screen?
打开 java 文件时,我首先看到的是空白屏幕,然后是启动画面布局。我有 java 文件为:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//Task
finish();
}
}, ARG_SPLASH_TIME);
在 xml
文件中,我只是输入 ImageView
并设置 android:src
值。
在 manifest
文件中,我在启动器模式下打开 Splash activity。
使用:
<item name="android:windowDisablePreview">true</item>
在您的 style.xml
应用主题文件中。
这是新发布的 Android Studio 的一个奇怪问题。第一次启动应用程序需要比平时更长的时间(看起来是白色的)。此问题仅在调试模式下发生,不会影响您发布的 APK。我也遇到了这个问题并找到了这个解决方案。
Settings/Preferences→构建、执行、部署→即时运行并取消选中即时运行
Instant run in Android Studio 2.0 (how to turn off)
您可以在启动画面中使用此样式 activity-
<style name="YourTheme">
<item name="android:windowBackground">@null</item>
</style>
好吧,白屏是 android 让系统感觉对用户响应更快的一种方式。用户点击应用程序并立即看到结果(应用程序)。
那么我们如何才能改变这种行为呢?
我们可以禁用此预览,如@Piyush 所写:
<item name="android:windowDisablePreview">true</item>
然而这会让您的应用程序感觉迟钝,我的意思是,您暂时看不到任何东西,然后您会看到您的 activity,这并不是您期望的结果。
更好的选择是在您的样式中使用 activity。
<item name="android:windowBackground">@drawable/bg</item>
这将更改您的应用程序的默认背景,您可以为应用程序放置预加载器图像,例如您的徽标。
两种情况下的用户都必须等待,但这感觉响应更快
终于得到我的答案Splash Screen in Right Way。我只是关注
在值中->styles.xml 我创建了闪屏背景图片
<style name="AppTheme.Splash" parent="AppTheme.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
</style>
对于 api19 以下,在 values-19->styles.xml 我使用了
<style name="AppTheme.Splash" parent="AppTheme.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
我从 SplashActivity 中删除了 setContentview()
并在 Manifest.xml
文件 android:theme="@style/AppTheme.Splash"
中添加了启动画面样式
有些答案现在不起作用,所以我更新了它并确保它没问题。首先创建您的 xml 启动文件
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/black" />
<item
android:width="@dimen/_145sdp"
android:height="@dimen/_30sdp"
android:drawable="@drawable/your_logo_here"
android:gravity="center" />
</layer-list>
在您的清单中:
<activity
android:name=".ui.SplashActivity"
android:theme="@style/Theme.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
最后是你的风格:
<style name="Theme.Splash" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
<!-- <item name="android:windowNoTitle">true</item>-->
<!-- <item name="android:windowActionBar">false</item>-->
<!-- <item name="android:windowFullscreen">true</item>-->
<!-- <item name="android:windowContentOverlay">@null</item>-->
</style>
你不需要布局文件,没必要,在你的 class 中删除 setContentView,像这样:
class SplashActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setUpView()
}
private fun setUpView() {
Handler(Looper.getMainLooper()).postDelayed({
val intent = Intent(this, MainActivity::class.java)
//startActivity(intent)
// finishAffinity()
}, 2000)
}
}
打开 java 文件时,我首先看到的是空白屏幕,然后是启动画面布局。我有 java 文件为:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//Task
finish();
}
}, ARG_SPLASH_TIME);
在 xml
文件中,我只是输入 ImageView
并设置 android:src
值。
在 manifest
文件中,我在启动器模式下打开 Splash activity。
使用:
<item name="android:windowDisablePreview">true</item>
在您的 style.xml
应用主题文件中。
这是新发布的 Android Studio 的一个奇怪问题。第一次启动应用程序需要比平时更长的时间(看起来是白色的)。此问题仅在调试模式下发生,不会影响您发布的 APK。我也遇到了这个问题并找到了这个解决方案。
Settings/Preferences→构建、执行、部署→即时运行并取消选中即时运行
Instant run in Android Studio 2.0 (how to turn off)
您可以在启动画面中使用此样式 activity-
<style name="YourTheme">
<item name="android:windowBackground">@null</item>
</style>
好吧,白屏是 android 让系统感觉对用户响应更快的一种方式。用户点击应用程序并立即看到结果(应用程序)。
那么我们如何才能改变这种行为呢?
我们可以禁用此预览,如@Piyush 所写:
<item name="android:windowDisablePreview">true</item>
然而这会让您的应用程序感觉迟钝,我的意思是,您暂时看不到任何东西,然后您会看到您的 activity,这并不是您期望的结果。
更好的选择是在您的样式中使用 activity。
<item name="android:windowBackground">@drawable/bg</item>
这将更改您的应用程序的默认背景,您可以为应用程序放置预加载器图像,例如您的徽标。
两种情况下的用户都必须等待,但这感觉响应更快
终于得到我的答案Splash Screen in Right Way。我只是关注
在值中->styles.xml 我创建了闪屏背景图片
<style name="AppTheme.Splash" parent="AppTheme.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
</style>
对于 api19 以下,在 values-19->styles.xml 我使用了
<style name="AppTheme.Splash" parent="AppTheme.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
我从 SplashActivity 中删除了 setContentview()
并在 Manifest.xml
文件 android:theme="@style/AppTheme.Splash"
有些答案现在不起作用,所以我更新了它并确保它没问题。首先创建您的 xml 启动文件
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/black" />
<item
android:width="@dimen/_145sdp"
android:height="@dimen/_30sdp"
android:drawable="@drawable/your_logo_here"
android:gravity="center" />
</layer-list>
在您的清单中:
<activity
android:name=".ui.SplashActivity"
android:theme="@style/Theme.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
最后是你的风格:
<style name="Theme.Splash" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
<!-- <item name="android:windowNoTitle">true</item>-->
<!-- <item name="android:windowActionBar">false</item>-->
<!-- <item name="android:windowFullscreen">true</item>-->
<!-- <item name="android:windowContentOverlay">@null</item>-->
</style>
你不需要布局文件,没必要,在你的 class 中删除 setContentView,像这样:
class SplashActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setUpView()
}
private fun setUpView() {
Handler(Looper.getMainLooper()).postDelayed({
val intent = Intent(this, MainActivity::class.java)
//startActivity(intent)
// finishAffinity()
}, 2000)
}
}