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


当前回答

试试这个,对我来说很管用:

下面去掉了活动的标题栏

 requestWindowFeature(Window.FEATURE_NO_TITLE);

下面消除了通知栏,使活动全屏显示

 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

(完整示例如下) 注意:这些方法是在我们设置活动的内容视图之前调用的

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Sets Application to full screen by removing action bar
        requestWindowFeature(Window.FEATURE_NO_TITLE);    
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_main); 

        // without this check, we would create a new fragment at each orientation change!
        if (null == savedInstanceState)
            createFragment();
    }

其他回答

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

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

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

如果你有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"

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

如果你使用一个活动包括启动屏幕,那么你可以这样做,如果你使用SherlockActionBar

getSupportActionBar().hide();

在启动画面之后,你可以用……

getSupportActionBar().show();

它应该与Android的原生ActionBar相同。