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


当前回答

嗨,我有一个简单的解决方案,使用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);

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

其他回答

最好和简单

requestWindowFeature (Window.FEATURE_NO_TITLE); getWindow () .setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

这是我用过的最好的方法 进入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(); 
        } 
    }

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

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

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

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

@牧师的解决方案工作。但这似乎也是谷歌的一些原生应用程序的问题:谷歌、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);

我仍然有空指针的错误,最后它帮助我调用第一个getWindow().requestFeature(),然后super.onCreate()

public void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
getActionBar().show();