摆脱操作栏

Getting rid of the Action Bar

我已经尝试摆脱操作栏,但我一直收到此错误

原因:java.lang.IllegalStateException:您需要使用 Theme.AppCompat 主题(或后代)与此 activity。

MainActivity.java

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);//I added this
    setContentView(R.layout.activity_main);

清单文件

 <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar" >//Changed this

我正在使用下面的主题

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

我已经阅读了很多帖子并尝试了它们,但应用程序总是崩溃。 请帮忙。

您需要使用另一个父主题:

<style name="AppTheme" parent=Theme.AppCompat.Light.NoActionBar">

而不是 "DarkActionBar"。

这样试试

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

你的主题是:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

在 styles.xml

中将以下代码添加到您的主题中
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>

试试这个: 在style.xml

<style name="AppTheme.NoTitleBar" parent="android:Theme.Light">
    <item name="android:windowNoTitle">true</item>

在manifest.xml

<activity
        android:name=".InitializationActivity"
        android:label="@string/app_name"
        android:noHistory="true"
        android:screenOrientation="sensorLandscape"
        android:theme="@style/AppTheme.NoTitleBar" >