我需要在我的蜂窝应用程序中实现启动画面。 我在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()。

其他回答

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

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

干杯

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

对我来说,最好的结果是用ThemeNoTitleBar创建一个活动,没有内容作为启动器。然后这个活动直接调用给对方。

当然,如果你愿意,你可以向Splash Activity添加内容,但在我的情况下,我只想直接显示应用程序。

清单:

<activity
        android:name="com.package.SplashActivity"
        android:theme="@android:style/Theme.Black.NoTitleBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

活动:

public class SplashActivity extends Activity{

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

    //start StartActivity
    Intent intent = new Intent(this, StartActivity.class);
    startActivity(intent);
    finish();
}

}

嗨,我有一个简单的解决方案,使用2个主题

启动画面主题(添加到清单): <style name="SplashTheme" parent="@android:style/Theme.Holo.NoActionBar"> <项目名称= " android: windowBackground " > @color /红> < /项目 > < /风格 正常的主题(添加到你的活动setTheme(R.style.Theme)): <style name="Theme" parent="@style/Theme. "Holo"> <item name="android:windowBackground">@color/blue</item> . > < /风格

支持SDK 10:

@Override    
public void onCreate(Bundle savedInstanceState) {

    setTheme(R.style.Theme);      
    super.onCreate(savedInstanceState);

      ...........
      ...........
}

解决方案已经发布了附带的副作用,第一个.show()调用没有为我动画动作栏。 我得到了另一个很好的解决方案,解决了这个问题:

创建一个透明的可绘制对象——就像这样:

<形状xmlns: android = " http://schemas.android.com/apk/res/android " > <固体 android:颜色= " # 00000000 " / > < / >形状

将实际的动作栏背景设置为你在动作栏上设置的一个不可见的自定义视图:

getSupportActionBar () .setCustomView (R.layout.actionbar_custom_layout); getSupportActionBar () .setDisplayOptions (ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar。DISPLAY_SHOW_CUSTOM | ActionBar。ActionBar.DISPLAY_SHOW_TITLE);

在onCreate中为动作栏设置透明背景:

getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.background_transparent));

重要提示:不要立即在onCreate中隐藏动作栏,但稍后会有一点延迟-例如,当布局创建完成时:

getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    getSupportActionBar().hide();
                }
            });

在你第一次调用.show()之前,设置自定义视图可见:

_actionbarRoot.setVisibility (View.VISIBLE); getSupportActionBar(),告诉();