2016-05-08 4 views
0

別の基本アクティビティを作成し、そのアクティビティを主アクティビティで呼び出すためにインテントを使用しました。階層的な親を主なアクティビティに設定しました。戻るボタンを押したときにメインアクティビティに戻るのではなくナビゲーションビューを再度表示するにはどうすればよいですか?助けが必要。別のアクティビティでNavigationViewを表示

MainActivityのXMLコード:

<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="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header_main" 
    app:menu="@menu/activity_main_drawer" /> 

二活性に私のXMLコード

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    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_first_" /> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="@dimen/fab_margin" 
    android:src="@android:drawable/ic_dialog_email" /> 

+0

説明を明確にするために、NavigationViewが開いているDrawerViewでメインアクティビティに戻る必要がありますか? –

+0

はい、それは私がしたいことです。 –

答えて

0

あなたはstartActivityForResuを試してみてくださいあなたの意図と一緒に旗を渡してください。メインアクティビティ(2番目のアクティビティから戻ったときに呼び出されます)でonActivityResultをオーバーライドし、送信したフラグを確認して、そのフラグを取得した場合は引き出しを開きます。

関連する問題