Android:无法还原原始工具栏

时间:2019-02-06 16:14:49

标签: android android-actionbar android-toolbar

我编辑了一个活动以添加带有菜单项的ActionBar,但是现在我无法恢复到原始工具栏。将styles.xml还原为这样

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

并从活动中删除了ActionBar代码

private Toolbar toolbar;

toolbar = findViewById(R.id.primaryToolbar);
setSupportActionBar(toolbar);

并从布局中删除

<include layout="@layout/main_toolbar"/>

并且类定义是默认的:

public class Main4Activity extends AppCompatActivity

但是我得到这个错误

This Activity already has an action bar supplied by the window decor. Do not request Window.
FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.

我编辑了styles.xml并添加了

<item name="windowActionBar">false</item>

然后我得到了

AppCompat does not support the current theme features: { windowActionBar: false, windowActionBarOverlay: false, android:windowIsFloating: false, windowActionModeOverlay: false, windowNoTitle: false }

AndroidManifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">

  <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  </application>

</manifest>

如何使用原始工具栏代替ActionBar?

0 个答案:

没有答案