【问题标题】:Blank page on application startup应用程序启动时出现空白页
【发布时间】:2013-08-16 08:53:23
【问题描述】:

我如何摆脱通常以应用程序名称作为标题的空白页面,该标题会在您启动应用程序时加载。我做了一些研究,发现最好的解释/解决方案是将应用程序的主题设置为 null,这样 android 系统就不会绘制该页面。

我已经尝试过了,但它不起作用,但原则上我认为应该这样做。

在我的styles.xml中我有

<style name="NoBackground" parent="android:Theme">
    <item name="android:windowBackground">@null</item>
</style>

在我的清单文件中,我有

<application
    android:name=".FIXR"
    android:allowBackup="true"
    android:icon="@drawable/launcher"
    android:label="@string/app_name"
    android:theme="@style/NoBackground" >

有没有更好的方法来解决这个问题?

【问题讨论】:

  • 我不明白你为什么要隐藏这个视图。这是在首次创建项目时创建的,以便为您提供基础。可以修改 java 文件和 xml 布局文件以满足您的需要。此屏幕是自动创建的,并在清单中设置为启动活动,即应用首次启动时加载的屏幕
  • 如何编辑此屏幕?
  • 查看我在回答中的编辑,附加启动画面
  • @GrayStatic 您没有解释您正在尝试做什么以及启动应用程序时用户应该看到什么。创建项目时,通常会创建一个名为 MainActivity.java 的活动文件和一个布局文件 main_activity.xml。在清单中它会有类似&lt;Activity android:name=".MainActivity"...android.Launcher 的东西我不记得我头顶的确切代码,但在某处它会说活动是启动器屏幕。 IE。首次打开应用时,将始终显示此屏幕
  • 我遇到了同样的问题...如果您解决了这个问题,请告诉我解决方案是什么...

标签: performance android-manifest android-theme android


【解决方案1】:

我用这个,它对我有用

<application
    android:name="com.example.G"
    android:icon="@drawable/ic_app"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar"
    >

【讨论】:

  • 也许您正在为您的启动器活动使用另一个主题。
  • 不,我没有为应用程序设置活动主题
【解决方案2】:

如果您的应用程序有服务,或者您在onCreate 方法上运行异步任务,则显示带有进程对话框的初始屏幕,并在加载所有源后切换到主屏幕。这是一种技术。

为了方便你工作,我截掉了部分代码:

launcher.xml

其实它是你的启动画面:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:src="@drawable/splashscreen" 
    android:scaleType="fitXY" />

<ProgressBar 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content"
    android:layout_gravity="center_horizontal|bottom" />

在您的主要活动中:

 setContentView(R.layout.launcher);

 mHandler = new Handler();

 //if Service is Ready: ....

 mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                startActivity(new Intent().setClass(LaunchActivity.this, OtherActivity.class).setData(getIntent().getData()));
                finish();
            }
        }, 1000);

希望对你有帮助

【讨论】:

  • 它实际上是我的启动画面造成的,我已经停止了这个类的繁重操作,但我仍然得到这个行为
【解决方案3】:

我认为它的显示是因为您的应用的首页需要时间来加载。您可能在 onCreate() 活动方法上做了太多工作。所以我建议在活动开始时尽量减少负载。这样就不会出现黑屏了。

希望你能理解!!

【讨论】:

  • 是的,我已经做了很多,但无济于事,难道没有解决办法吗?
  • 你在活动负载上做什么??
  • 使用异步任务下载 JSON 文件
  • 我建议打开闪屏 2 3 秒。然后打开您的活动并执行后台任务,以免出现黑屏。有时当您的应用程序也很重负载时会发生这种情况。意味着很多drawables或布局。那个时候也可能发生。
【解决方案4】:

style.xml 创建:

<style name="SplashPage">
    <item name="android:windowBackground">@color/white</item>
</style>

然后在您的启动器活动中的AndroidManifest.xml 中,指定活动主题:

<activity
    android:name=".activity.MainActivity"
    android:label="@string/title_activity_main"
    android:theme="@style/SplashPage"
    android:screenOrientation="portrait" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

【讨论】:

    【解决方案5】:

    尝试下面的代码行,将这些行添加到您的 res/values/styles.xml 中:

    --------

    <style name="SplashScreen">
        <item name="android:padding">0dp</item>
        <item name="android:windowBackground">@android:color/black</item>
        <item name="android:windowFrame">@null</item>
    </style>
    

    并在您的清单文件中将其作为样式在您的活动标签下传递为:

    <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.mpg.myapp.MainActivity"
        android:theme="@style/SplashScreen"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
    
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    

    或许这会对你有所帮助。

    【讨论】: