因此,首先,我一直在遵循有关使导航抽屉正常工作的教程。当我到达他要测试的部分时,他可以点击汉堡包打开侧边栏,而我的则不行。我可以滑动以将其打开,但是,轻按按钮不会执行任何操作。似乎没有其他人有这个问题
主要活动XML文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dumby"
android:layout_centerInParent="true" />
</RelativeLayout>
<ListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#818181"
android:dividerHeight="1dp"
android:background="#E3F2FD" />
主要活动CS文件
public class MainActivity : AppCompatActivity
{
private SupportToolbar mToolbar;
private ActionBarDrawerToggle mDrawerToggle;
private DrawerLayout mDrawerLayout;
private ListView mLeftDrawer;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
mToolbar = FindViewById<SupportToolbar>(Resource.Id.toolbar);
mDrawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
mLeftDrawer = FindViewById<ListView>(Resource.Id.left_drawer);
mDrawerToggle = new ActionBarDrawerToggle(
this,
mDrawerLayout,
Resource.String.openDrawer,
Resource.String.closeDrawer);
SetSupportActionBar(mToolbar);
SupportActionBar.SetDisplayHomeAsUpEnabled(true);
mDrawerLayout.AddDrawerListener(mDrawerToggle);
mDrawerToggle.SyncState();
}
public override bool OnOptionsItemSelected(IMenuItem item)
{
mDrawerToggle.OnOptionsItemSelected(item);
//Toast.MakeText(this, "EEEE", ToastLength.Long);
return base.OnOptionsItemSelected(item);
}
这里是操作栏抽屉切换类,以防万一
using SupportActionBarDrawerToggle = Android.Support.V7.App.ActionBarDrawerToggle;
namespace Android_App_V2
{
class ActionBarDrawerToggle: SupportActionBarDrawerToggle
{
private AppCompatActivity mHostActivity;
private int mClosedResource;
private int mOpenResource;
public ActionBarDrawerToggle(AppCompatActivity host, DrawerLayout drawerLayout, int openedResource,
int closedResource) : base(host, drawerLayout, openedResource, closedResource)
{
mHostActivity = host;
mOpenResource = openedResource;
mClosedResource = closedResource;
}
public override void OnDrawerOpened(View drawerView)
{
base.OnDrawerOpened(drawerView);
}
public override void OnDrawerClosed(View drawerView)
{
base.OnDrawerClosed(drawerView);
}
public override void OnDrawerSlide(View drawerView, float slideOffset)
{
base.OnDrawerSlide(drawerView, slideOffset);
}
public override bool OnOptionsItemSelected(IMenuItem item)
{
return base.OnOptionsItemSelected(item);
}
}}