我需要在我的蜂窝应用程序中实现启动画面。 我在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,我发现没有办法再次显示它。


当前回答

只需将此添加到MainActivity的onCreate函数中。

val actionBar = supportActionBar?.apply { hide() }

其他回答

如果你使用一个活动包括启动屏幕,那么你可以这样做,如果你使用SherlockActionBar

getSupportActionBar().hide();

在启动画面之后,你可以用……

getSupportActionBar().show();

它应该与Android的原生ActionBar相同。

嗨,我有一个简单的解决方案,使用2个主题

启动画面主题(添加到清单): <style name="SplashTheme" parent="@android:style/Theme.Holo.NoActionBar"> <项目名称= " android: windowBackground " > @color /红> < /项目 > < /风格 正常的主题(添加到你的活动setTheme(R.style.Theme)): <style name="Theme" parent="@style/Theme. "Holo"> <item name="android:windowBackground">@color/blue</item> . > < /风格

支持SDK 10:

@Override    
public void onCreate(Bundle savedInstanceState) {

    setTheme(R.style.Theme);      
    super.onCreate(savedInstanceState);

      ...........
      ...........
}

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

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

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

只需将其添加到您的styles.xml中

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

这是我用过的最好的方法 进入java文件,在onCreate之后:

@Override
    protected void onCreate(Bundle savedInstanceState) 
    { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 

        // Take instance of Action Bar 
        // using getSupportActionBar and 
        // if it is not Null 
        // then call hide function 
        if (getSupportActionBar() != null) { 
            getSupportActionBar().hide(); 
        } 
    }