【问题标题】:Android App bar menu disappears every time I create a new activity每次创建新活动时,Android 应用栏菜单都会消失
【发布时间】:2017-02-08 01:42:12
【问题描述】:

为什么每次我做一个新的活动?

例如代码:

Intent intent = new Intent(getApplicationContext(), NextActivity.class;
startActivity(intent);

应用栏菜单项不见了? :(

谁能告诉我每次打开一个新活动时该怎么做,总是出现相同的应用栏和菜单?

已编辑:

**activity.xml**



                <?xml version="1.0" encoding="utf-8"?>
            <android.support.v4.widget.DrawerLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                xmlns:tools="http://schemas.android.com/tools"
                android:id="@+id/drawer_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                tools:openDrawer="start">

                <include
                    layout="@layout/app_bar_main"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />

                <android.support.design.widget.NavigationView
                    android:id="@+id/nav_view"
                    android:layout_width="wrap_content"
                    android:layout_height="400dp"
                    android:layout_gravity="start"
                    android:fitsSystemWindows="true"
                    app:headerLayout="@layout/nav_header_main"
                    app:menu="@menu/activity_main_drawer" />

        </android.support.v4.widget.DrawerLayout>


**activity_intention.xml:**
    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:openDrawer="start">




*I'll also include the app_bar_main.xml*




        <?xml version="1.0" encoding="utf-8"?>
        <android.support.design.widget.CoordinatorLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            tools:context="com.example.beminix.dcar.MainActivity">

            <android.support.design.widget.AppBarLayout
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:theme="@style/AppTheme.AppBarOverlay">

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary"
                    app:popupTheme="@style/AppTheme.PopupOverlay" />

            </android.support.design.widget.AppBarLayout>

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



        </android.support.design.widget.CoordinatorLayout>

The toolbar that I want to keep using The 3 menu icons are gone so as the title

【问题讨论】:

  • 您可以发布 NextActivity 的 xml 吗?以及显示 App Bar 的 MainActivity 的 xml
  • @BlancheNeedsHelp 检查 NextActivity 视图的内容 检查主题,并在发布问题时确保发布所有相关内容
  • 您需要在每个活动中设置选项菜单
  • 我是安卓新手。怎么做? @VishalPatoliyaツ
  • 分享屏幕截图@BlancheNeedsHelp

标签: android android-intent appbar menu-items


【解决方案1】:

这是不同的解决方案,但在我的项目中工作当前。在 Activity 中使用片段并在单击调用另一个片段时使用两个片段,你将获得 1 个菜单栏,如果你想要活动,你必须在每个活动中创建操作栏

【讨论】:

  • 使用工具栏只是在所有活动中复制过去
  • 我知道片段,但我需要创建一个新活动,因为我需要在该活动中放置一个搜索视图和列表视图。我的工具栏有图标,我必须这样做,因为这就是我们的状态图应该做的。
  • 我从这里的帖子中读到我无法将搜索视图放在片段中。 :(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-03-22
  • 1970-01-01
  • 1970-01-01
  • 2019-03-20
  • 2014-01-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多