我有一个Android应用程序,在启动时显示白色屏幕2秒.我的其他应用程序不这样做,但这个应用程序.我还实现了一个启动画面,希望能解决这个问题.我应该增加闪屏的睡眠时间吗?谢谢.
每当我的应用程序启动时,都会在短时间内显示白色背景.尽管使用了启动画面,问题仍然存在.我想将启动屏幕设置为黑色而不是默认的白色!
这是我的启动画面活动:
public class SplashActivity extends Activity {
private static String TAG = SplashActivity.class.getName();
private static long SLEEP_TIME = 1; // Sleep for some time
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE); // Removes title bar
setContentView(R.layout.splash);
// Start timer and launch main activity
IntentLauncher launcher = new IntentLauncher();
launcher.start();
}
private class IntentLauncher extends Thread {
/**
* Sleep for some time and than start new activity.
*/
@Override
public void run() {
try {
// Sleeping
Thread.sleep(SLEEP_TIME*1000); …Run Code Online (Sandbox Code Playgroud) 我已使用主要变体颜色作为整个应用程序的背景,但在 UI 最初加载时我仍然看到白色屏幕。有什么办法解决吗?
编辑:我创建了一个新的空项目并应用了@Philip Dukhov 的以下建议。结果还是一样。首先出现白色屏幕,并在 Surface 开始加载之前在屏幕上停留至少两秒钟。
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
SOIssueReproduceTheme {
Surface(
color = MaterialTheme.colors.primaryVariant,
modifier = Modifier.fillMaxSize()
) {
Greeting("Android")
}
}
}
}
}
@Composable
fun Greeting(name: String) {
Text(text = "Hello $name!")
}
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助!
当我单击应用程序图标并开始运行应用程序时,它将显示为白色屏幕1秒钟.
我不知道为什么.
有没有想法清除这个白色屏幕并直接进入我的活动?
当我启动我的应用程序时,我会在启动闪屏之前看到白屏几秒钟.
我想知道我的应用程序的大小是否会影响它(它是17.7MB).或者是因为我的测试设备是旧的(HTC Desire HD)并且有太多数据被破坏了?
或者这是正常的行为?或者问题可能在我的代码中,这是在...
部分清单:
<activity android:name=".SplashView"
android:noHistory="true"
android:screenOrientation="portrait"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"
android:configChanges="orientation" >
<intent-filter >
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
飞溅活动:
public class SplashView extends SherlockActivity {
private final int SPLASH_DISPLAY_LENGHT = 1000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.splash_view);
try {
RefreshRatingsTask urt = new RefreshRatingsTask();
urt.execute();
} catch (Exception e) {
// ignore
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() …Run Code Online (Sandbox Code Playgroud)