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


当前回答

我知道发布链接不是最好的方法,但我强烈建议你阅读下面谷歌自己的文档。这是关于如何控制你的系统ui(像动作栏,导航栏等)的官方android文档。不幸的是,这些信息太多了,不能直接发布,但在阅读完这篇文章后,你将确切地了解如何显示和隐藏功能,无论你开发的是什么版本,它是如此简单!

如果链接发生变化,它可以在培训->入门->用户界面最佳实践->管理系统ui的官方android文档下找到

https://developer.android.com/training/system-ui/index.html

其他回答

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

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

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

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

如果你正在使用ActionBarSherlock,那么在你的活动中使用Theme. sherlock . noactionbar Theme

<activity 
    android:name=".SplashScreenActivity"
    android:theme="@style/Theme.Sherlock.NoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

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

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

干杯

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

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

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