我需要在我的蜂窝应用程序中实现启动画面。 我在activity的onCreate中使用这段代码来显示splash:

setContentView(R.layout.splash);
getActionBar().hide();

这段代码将显示主UI:

setContentView(R.layout.main);
getActionBar().show();

但在onCreate被调用和飞溅出现之前,有一小段时间,当动作栏显示。

我怎样才能使动作栏不可见?

我尝试将主题应用于没有动作条的活动:

<item name="android:windowActionBar">false</item>

但在这种情况下,getActionBar()总是返回null,我发现没有办法再次显示它。


当前回答

把你的启动画面放在一个单独的活动,并使用startActivityForResult从你的主活动的onCreate方法来显示它。根据医生的说法,这是因为:

作为一个特殊情况,如果你在你的活动的初始onCreate(Bundle savedInstanceState)/onResume()期间用requestCode >= 0调用startActivityForResult(),那么你的窗口将不会显示,直到从启动的活动返回结果。这是为了避免重定向到另一个活动时可见的闪烁。

你可能只应该在onCreate参数为空时这样做(指示您的活动的新启动,而不是由于配置更改而重新启动)。

其他回答

试试这个,对我来说很管用:

下面去掉了活动的标题栏

 requestWindowFeature(Window.FEATURE_NO_TITLE);

下面消除了通知栏,使活动全屏显示

 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

(完整示例如下) 注意:这些方法是在我们设置活动的内容视图之前调用的

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Sets Application to full screen by removing action bar
        requestWindowFeature(Window.FEATURE_NO_TITLE);    
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_main); 

        // without this check, we would create a new fragment at each orientation change!
        if (null == savedInstanceState)
            createFragment();
    }

@牧师的解决方案工作。但这似乎也是谷歌的一些原生应用程序的问题:谷歌、play store、talk。还有其他大型应用程序,如skype。

编辑:下面的解决方案给了我的问题actionbarsherlock api < 4.0,原因是setTheme不工作前冰淇淋三明治

在应用程序或活动标签的清单中添加以下内容:

android:theme="@style/Theme.NoActionBar"

然后在你的主要活动中

    // Set theme
    setTheme(R.style.YOUR_THEME);
    getSupportActionBar().setTitle(R.string.title);

    // Start regular onCreate()
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

如果你有null,因为你正在使用支持库,而不是getActionBar(),你需要调用getSupportActionBar()。

对于Splashscreen,你应该在manifest中使用这一行,而不是使用getActionBar()

<item name="android:windowActionBar">false</item>

当Splash活动在主活动中完成时,使用下面或什么都没有

<item name="android:windowActionBar">true</item>

如果你正在使用ActionBarSherlock,那么在你的活动中使用Theme. sherlock . noactionbar Theme

<activity 
    android:name=".SplashScreenActivity"
    android:theme="@style/Theme.Sherlock.NoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>