2016-05-08 4 views
0

Я создал еще одну базовую деятельность и намерен называть ее основной деятельностью. Я установил родительский элемент иерархии для основной активности. Как показать навигационное окно снова, а не возвращаться к его основной активности при нажатии кнопки «Назад»? Нужна помощь.Показать навигациюПосмотреть другую активность

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

Для уточнения, хотите ли вы перейти к основному действию с помощью DrawerView, который содержит NavigationView open? –

+0

Да, это то, что я хочу сделать. –

ответ

0

Вы можете попробовать startActivityForResu и пропустите флаг вместе с вашими намерениями. Переопределите onActivityResult в своем основном действии (он будет вызываться, когда вы вернетесь со второго действия), проверьте флаг, который вы отправили, и откройте ящик, если вы получите этот флаг.

Смежные вопросы