Android 设置活动主题WindowBackground导致ActionBar为空

Android 设置活动主题WindowBackground导致ActionBar为空,android,android-actionbar,themes,Android,Android Actionbar,Themes,我做了一个小改动,为我的主要活动设置了WindowBackground。这样做会导致ActionBar变为null 首先,我添加了一个新样式: <style name="SplashTheme" parent="android:Theme.Light" > <item name="android:windowBackground">@android:color/black</item> </style> 我错过什么了吗?我需要做

我做了一个小改动,为我的主要活动设置了WindowBackground。这样做会导致ActionBar变为null

首先,我添加了一个新样式:

  <style name="SplashTheme" parent="android:Theme.Light" >
     <item name="android:windowBackground">@android:color/black</item>
  </style>
我错过什么了吗?我需要做什么才能创建ActionBar


谢谢。

您使用
主题.Light
作为父主题。此主题在Android中用作从v1到v10的默认主题<代码>操作栏是在v11中引入的,因此当使用旧主题时,
操作栏
将为空。如果要使用
ActionBar
,请使用
Theme.Holo.Light
Theme.Material.Light
作为父级。

应用程序的主题是什么?相同的:Theme.Light确保已为您的活动调用了setContentView(视图),否则getActionBar()将返回null。
    <activity
        android:name=".main.MainActivity"
        android:theme="@style/SplashTheme"
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
public void onCreate (Bundle savedInstanceState)
{
  super.onCreate(savedInstanceState);

  LayoutInflater inflater = getLayoutInflater();
  View contentView = inflater.inflate (R.layout.main_activity, null);
  setContentView (contentView);

  ActionBar b = getActionBar();
  ...
}