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


当前回答

在阅读了所有可用选项后,我发现最好的方法是设置主主题而不使用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 !

其他回答

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

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

对于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 !

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

你可以用这个:

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

getActionBar().hide();

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

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

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