【问题标题】:How to get rid of this default splash screen?如何摆脱这个默认的启动画面?
【发布时间】:2015-08-24 01:29:11
【问题描述】:

我尝试在我的应用中添加启动画面,虽然它们确实显示在主 Activity 之前,但无论如何该屏幕也始终显示:

这是 MainActivity 的代码:

public class MainActivity extends Activity implements WelcomeFragment.StartQuestions, QuestionFragment.QuestionsAnswered {
@Override
protected void onCreate(Bundle savedInstanceState) {
    Parse.enableLocalDatastore(this);
    Parse.initialize(this, "***************************", "*****************************");
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.activity_main);
    loadingIcon = (ProgressBar) findViewById(R.id.loadingIcon);
    loadingIcon.setVisibility(View.GONE);
    checkInternetConnection();

    showWelcomeScreen();
}
}

showWelcomeScreen():

public void showWelcomeScreen(){
    Fragment fragment = getFragmentManager().findFragmentById(R.id.fragmentContainer);

    if (fragment == null){
        fragment = new  WelcomeFragment();
        getFragmentManager().beginTransaction()
                .add(R.id.fragmentContainer, fragment)
                .commit();
    } else {
        fragment = new  WelcomeFragment();
        getFragmentManager().beginTransaction()
                .replace(R.id.fragmentContainer, fragment)
                .commit();
    }
}

activity_main.xml:

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

<RelativeLayout
    android:id="@+id/loadingPanel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    >

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminate="true" android:id="@+id/loadingIcon"/>
</RelativeLayout>

在 MainActivity 中,我已经指定移除顶栏: this.requestWindowFeature(Window.FEATURE_NO_TITLE);

应用程序本身没有栏。我在清单中默认放置的任何活动(作为启动屏幕)仍然会在应用启动时通过上面显示的屏幕进行。

【问题讨论】:

  • 发布您的主要活动代码。
  • 您需要将相关代码添加到您的问题中,以便任何人帮助您
  • 对不起。我以为这是每个人的默认屏幕,无论他们的活动代码如何
  • 发布showWelcomeScreen()
  • developer.android.com/training/system-ui/status.html 这将向您展示如何隐藏状态栏(假设这是您想要做的)。

标签: android android-activity splash-screen


【解决方案1】:

你不能。 Android 将始终在您的 Activity 实际加载之前尝试仅使用主题的属性来显示某些内容。

事实上,correct way to build a splash screen 涉及利用这一事实并自定义您的主题,以便在此期间显示的内容您的初始屏幕。

【讨论】:

  • 谢谢!正是我想要的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多