2017-02-08 64 views
0

爲什麼每次我進行新活動?每當我創建新活動時,Android應用欄菜單都會消失

例如代碼:

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

+0

你可以發佈NextActivity的xml嗎?以及顯示App Bar的MainActivity的xml –

+0

@BlancheNeedsHelp檢查您的NextActivity視圖的內容檢查主題並在發佈問題時確保您發佈所有相關的東西 –

+2

您需要設置選項菜單每個活動 –

回答

0

這是不同的解決方案,但工作電流在我的項目.use片段在活動和點擊調用另一個片段使用兩個片段你會得到1個菜單欄,如果你想活動你必須做出行動b ar每個活動

+0

使用工具欄只是複製過去的所有活動 –

+0

我知道片段,但我需要做一個新的活動,因爲我需要在該活動中放置搜索視圖和列表視圖。我的工具欄上有圖標,我必須按照這種方式來操作,因爲這是我們的狀態圖應該如何操作的。 – AnyHelpPls

+0

我從一篇文章的回答中讀到,我無法在搜索框中放入搜索視圖。 :( – AnyHelpPls

相關問題