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


当前回答

创建两个样式:

<style name="AppThemeNoBar" parent="Theme.AppCompat.Light">
     <item name="android:windowNoTitle">true</item>
</style>

<style name="AppThemeBar" parent="Theme.AppCompat.Light">
    <item name="android:windowNoTitle">false</item>
</style>

将AppThemeNoBar设置为应用程序主题,将AppThemeBar设置为您想要显示actionbar的活动 使用两种样式,当视图加载时,你将看不到操作栏。

检查这个链接Android:隐藏操作栏,同时查看加载

其他回答

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

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

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

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

创建两个样式:

<style name="AppThemeNoBar" parent="Theme.AppCompat.Light">
     <item name="android:windowNoTitle">true</item>
</style>

<style name="AppThemeBar" parent="Theme.AppCompat.Light">
    <item name="android:windowNoTitle">false</item>
</style>

将AppThemeNoBar设置为应用程序主题,将AppThemeBar设置为您想要显示actionbar的活动 使用两种样式,当视图加载时,你将看不到操作栏。

检查这个链接Android:隐藏操作栏,同时查看加载

这可能很方便 把这个加到你的舱单上

 android:theme="@android:style/Theme.Light.NoTitleBar" 

干杯

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