支持行动栏

时间:2015-09-23 08:46:32

标签: android xml

当我将工具栏应用到应用程序时遇到问题,当我尝试运行该应用程序时它崩溃了。

style.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->

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

    </style>



<android.support.v7.widget.Toolbar
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:id="@+id/toolbar"
        android:minHeight="?attr/actionBarSize"
        />

Main.java

setContentView(R.layout.activity_main);

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

的Manifest.xml

<application android:name="com.example.app.AppController" android:label="@string/app_name" android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:theme="@style/Theme.AppCompat.Light">

logcat的:

  

此活动已有窗口装饰提供的操作栏。请勿在主题中请求Window.FEATURE_SUPPORT_ACTION_BAR并将windowActionBar设置为false以使用工具栏。

2 个答案:

答案 0 :(得分:1)

您的清单错误,即应用主题为应用程序。

将其更改为:

android:theme="@style/AppTheme"

因为目前您使用样式WITH操作栏。

答案 1 :(得分:1)

在我的代码中,我禁用了该行: // setSupportActionBar(栏);

在主要课程上