Forum Xamarin.Android

Drawable Menu When open new page

When I want to open the new page, the toolbar disappears and cannot be returned.
In drawable menu items click, my new activity start.

My activity for new page

My menu when ı click:

The second page haven't got toolbar or drawable menu:

Best Answer

  • jezhjezh Member, Xamarin Team Xamurai
    Accepted Answer

    The second page haven't got toolbar or drawable menu

    If you want to keep the toolbar when you click a button to navigate to another page, you can create a Custom Android Toolbar for you page.

    1.define a layout (toolbar.axml)in folder layout

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:layout_height="60dp"
        android:fitsSystemWindows="true"
    
        app:contentInsetLeft="0dp"
        app:contentInsetStart="0dp">
    
        <LinearLayout  
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:singleLine="true"
                android:src="@drawable/back"
                android:textColor="#ffffff"
                android:textSize="16sp"
                android:visibility="visible"/>
    
            <TextView
                android:gravity="center"
                android:layout_weight="1"
                android:id="@+id/txt_main_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="Title"
                android:textColor="@android:color/white"
                android:textSize="20sp"
                android:visibility="visible"/>
        </LinearLayout>
    </android.support.v7.widget.Toolbar>
    

    2.Use it like this:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:local="http://schemas.android.com/apk/res-auto"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />
    
    </RelativeLayout>
    

    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

Answers

  • CastielTRCastielTR Member ✭✭

    up up up

  • jezhjezh Member, Xamarin Team Xamurai
    Accepted Answer

    The second page haven't got toolbar or drawable menu

    If you want to keep the toolbar when you click a button to navigate to another page, you can create a Custom Android Toolbar for you page.

    1.define a layout (toolbar.axml)in folder layout

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:layout_height="60dp"
        android:fitsSystemWindows="true"
    
        app:contentInsetLeft="0dp"
        app:contentInsetStart="0dp">
    
        <LinearLayout  
            android:gravity="center_vertical"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:singleLine="true"
                android:src="@drawable/back"
                android:textColor="#ffffff"
                android:textSize="16sp"
                android:visibility="visible"/>
    
            <TextView
                android:gravity="center"
                android:layout_weight="1"
                android:id="@+id/txt_main_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="Title"
                android:textColor="@android:color/white"
                android:textSize="20sp"
                android:visibility="visible"/>
        </LinearLayout>
    </android.support.v7.widget.Toolbar>
    

    2.Use it like this:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:local="http://schemas.android.com/apk/res-auto"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />
    
    </RelativeLayout>
    

    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

Sign In or Register to comment.