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


当前回答

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

其他回答

如果你正在使用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>

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

下面去掉了活动的标题栏

 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();
    }

我还试图在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>

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

最好的方法是将第一个活动作为空白活动和您想要放置的内容,然后在一段时间后触发另一个活动。 按照这种方法,你可以将第一个活动作为你的启动画面,而不需要操作栏或任何东西。 这是我的第一个活动

package com.superoriginal.rootashadnasim.syllabus;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class first_screen extends AppCompatActivity {



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_first_screen);


    final Handler h=new Handler();
    h.postDelayed(new Runnable() {
        @Override
        public void run() {
            Intent intent=new     Intent(getApplicationContext(),DrawerChooseBranchMainActivity.class);
            startActivity(intent);
        }
    },2000);

}
}

之后,你可以把任何一个活动作为第一个活动 如果你想在任何屏幕上都没有动作栏,那么只需在你的样式中添加这个

    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">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 !