问题描述
限时送ChatGPT账号..在我的 xamarin android 应用程序中,我有一个正确的导航栏和一个自定义工具栏.导航栏的代码是这样的
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" />
工具栏的代码是这样的
<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>
我想在用户按下 id = right_nav 的 ImageView 时打开导航栏.我该怎么做?
I wanna open the navigation bar when the user press the ImageView with id = right_nav. How can i do this?
推荐答案
Xamarin 机器人.使用自定义工具栏中的按钮打开右侧导航栏
Xamarin android. Open right navigation bar with button from custom toolbar
将您的 NavigationView
放入 DrawerLayout
,例如:
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/apk/res/android"
xmlns:app="http://schemas.android/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>
然后,正如@Federico Navarrete 指出的那样,为您的 ImageView
定义一个点击事件:
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);
};
这篇关于Xamarin 安卓.使用自定义工具栏中的按钮打开右侧导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论