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

问题描述 投票:0回答:1

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

首先我添加了新样式:

  <style name="SplashTheme" parent="android:Theme.Light" >
     <item name="android:windowBackground">@android:color/black</item>
  </style>

然后,我更改了主要活动的清单以引用样式:

    <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>

就是这样。操作栏为空。例如,在此代码中为null:

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

我想念什么吗?我需要怎么做才能创建ActionBar?

谢谢。

android android-actionbar themes
1个回答
0
投票

您使用Theme.Light作为父主题。从v1到v10,该主题在Android中用作默认主题。 v11中引入了Actionbar,因此当使用旧主题时,ActionBar将为空。如果要使用ActionBar,请使用Theme.Holo.LightTheme.Material.Light作为父项。

© www.soinside.com 2019 - 2024. All rights reserved.