我需要在我的蜂窝应用程序中实现启动画面。 我在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);

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

其他回答

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

2015年,使用支持v7库与AppCompat主题,设置此主题为您的活动。

<style name="AppTheme.AppStyled" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimaryDark">@color/md_indigo_100</item>
    <item name="colorPrimary">@color/md_indigo_500</item>
    <item name="colorAccent">@color/md_red_500</item>
    <item name="android:textColorPrimary">@color/md_white_1000</item>
    <item name="android:textColor">@color/md_purple_500</item>
    <item name="android:textStyle">bold</item>
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

你可以用这个:

getSupportActionBar () hide ();如果不奏效,试试下面这个:

getActionBar().hide();

如果以上都不行,试试下面的方法:

在你的目录= res/values/style.xml,打开style.xml ->有属性父更改为父="Theme.AppCompat.Light.DarkActionBar"

如果这一切都不奏效。我也不知道了。但对我来说很管用。

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

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

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

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

在阅读了所有可用选项后,我发现最好的方法是设置主主题而不使用ActionBar,然后在所有活动的父级代码中设置MyTheme。

清单:

<application
...
        android:theme="@android:style/Theme.Holo.Light.NoActionBar"
...>

BaseActivity:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTheme(R.style.GreenHoloTheme);
}

这种方法可以帮助我在应用程序启动时避免使用ActionBar !