溢出和其他菜单项在Android上不显示

溢出和其他菜单项在Android上不显示,android,android-actionbar,android-appcompat,android-toolbar,android-menu,Android,Android Actionbar,Android Appcompat,Android Toolbar,Android Menu,我目前正在尝试添加一个工具栏作为操作栏,但除了要显示应用程序的名称之外,我很难获得任何东西。我正在从appcompat添加工具栏,并创建了菜单xml文件。为了将两者联系起来,我是否需要采取必要的措施 以下是我的活动xml: <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tool

我目前正在尝试添加一个工具栏作为操作栏,但除了要显示应用程序的名称之外,我很难获得任何东西。我正在从appcompat添加工具栏,并创建了菜单xml文件。为了将两者联系起来,我是否需要采取必要的措施

以下是我的活动xml:

    <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".canvas.CanvasActivity"
    >


    <com.alastech.andyluo.crowdshout_androidapp.canvas.CanvasTest
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/view"
        android:layout_gravity="center" />

    <android.support.v7.widget.Toolbar
        android:id="@+id/canvas_toolbar"
        android:layout_width="match_parent"
        android:elevation="0dp"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

</FrameLayout>

为了清楚起见,我完全遵循本教程:


非常感谢您的帮助,谢谢

在活动中添加以下方法

@Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // use sample_actions or wheever your xml for the menufile name below
            getMenuInflater().inflate(R.menu.sample_actions, menu);
            return true;
        }

在活动中添加以下方法

@Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // use sample_actions or wheever your xml for the menufile name below
            getMenuInflater().inflate(R.menu.sample_actions, menu);
            return true;
        }

这是一个活动还是一个片段?您是否设置了setHasOptionMenu(true);如果您使用的是一个片段,这是一个活动,这是一个活动还是片段?您是否设置了setHasOptionMenu(true);如果你使用的是一个片段,这是一个有趣的活动,我在前面看到了一个类似的解决方案,并尝试了它,但没有成功。这很好用!非常感谢。有趣的是,我在前面看到了一个类似的解决方案,并尝试了它,但没有成功。这很好用!非常感谢。