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


当前回答

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

其他回答

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

我还试图在Android 2.2上隐藏操作栏,但这些解决方案都不起作用。一切都以崩溃告终。我检查了DDMS日志,它告诉我使用“Theme.AppCompat”。最后,我通过改变android:theme="@android:style/ theme . holo . light . noactionbar "行解决了这个问题

为android:主题= " @style / Theme.AppCompat。NoActionBar”,它工作,但界面是黑暗的。

然后我尝试了android:theme="@style/ theme . appcompat . light。NoActionBar”,最终得到了我想要的。

之后,当我在开发者网站上搜索“AppCompat”时,我得到了这个。

所以我认为Android 2.2的解决方案是

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

对我的英语很抱歉,一如既往。

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

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

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

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

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

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