Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

xamarin.android - Xamarin android. Open right navigation bar with button from custom toolbar

In my xamarin android app I have a right navigation bar and a custom toolbar. The code for navigation bar is this

<android.support.design.widget.NavigationView
 android:layout_width="wrap_content"
 android:layout_height="match_parent"
 android:layout_gravity="right"
 android:id="@+id/right_nav_view"
 app:menu="@menu/menu_navigation_swipe" />

And the code for toolbar is this

<android.support.v7.widget.Toolbar
 android:id="@+id/toolbar"
 android:layout_width="match_parent"
 android:layout_height="45dp"
 android:minHeight="?attr/actionBarSize"
 android:background="@drawable/rectangle"
 android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
 app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
  <RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/HomeButton"
        android:layout_gravity="center"
        android:src="@drawable/logo"
        android:clickable="true" />

  <ImageView
          android:padding="10dp"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:id="@+id/right_nav"
         android:layout_alignParentEnd="true"
         android:layout_alignParentRight="true"
         android:src="@drawable/icon_settings"
         android:clickable="true" />

    </RelativeLayout>
</android.support.v7.widget.Toolbar>

I wanna open the navigation bar when the user press the ImageView with id = right_nav. How can i do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Xamarin android. Open right navigation bar with button from custom toolbar

Place your NavigationView into a DrawerLayout, for example:

<?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"
    android:id="@+id/drawer_layout"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true">

  <!-- I place your Toolbar in this include_list_viewpager layout -->
  <include layout="@layout/include_list_viewpager"/>

  <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="right"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/drawer_view"/>

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

Then, as @Federico Navarrete has pointed out, define a click event for your ImageView:

DrawerLayout drawerLayout = FindViewById<DrawerLayout> (Resource.Id.drawer_layout);

ImageView right_nav = FindViewById<ImageView>(Resource.Id.right_nav);

right_nav.Click += (s, e) =>
{
     drawerLayout.OpenDrawer(Android.Support.V4.View.GravityCompat.End);
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...