大家好我正在Android应用程序中的汉堡菜单上工作,我的问题是汉堡菜单放在错误的地方(几步下来)。我需要在窗口工具栏下面的汉堡菜单。请在这方面帮助我。 我的java代码:
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(mDrawerToggle);
// Creating Hamburger Menu
final TextView userName_ham = (TextView) this.findViewById(R.id.userName_hamburger);
ParseQuery<DriverDetails> query = new ParseQuery<DriverDetails>("driverDetails");
Log.d(TAG_NAME, "Driver Phone No" + driverPhoneNo);
query.whereEqualTo("PhoneNo", driverPhoneNo);
query.findInBackground(new FindCallback<DriverDetails>() {
@Override
public void done(List<DriverDetails> objects, ParseException e) {
if (e == null) {
if (objects.size() != 0) {
driverName = objects.get(0).getString("driverNameFirst");
Log.d(TAG_NAME, "DriverName inside" + driverName);
editor.putString("driverName", driverName);
editor.apply();
userName_ham.setText("Welcome " + driverName);
}
}
}
});
Log.d(TAG_NAME, "DriverName" + driverName);
mNavItems.add(new NavItem("Earnings", R.drawable.earnings));
mNavItems.add(new NavItem("History", R.drawable.history));
mNavItems.add(new NavItem("About", R.drawable.about));
mNavItems.add(new NavItem("Share", R.drawable.share));
mNavItems.add(new NavItem("Notification", R.drawable.notification));
mNavItems.add(new NavItem("Settings", R.drawable.settings));
mNavItems.add(new NavItem("Logout", R.drawable.logout));
// DrawerLayout
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
// Populate the Navigation Drawer with options
mDrawerPane = (RelativeLayout) findViewById(R.id.drawerPane);
mDrawerList = (ListView) findViewById(R.id.navList);
DrawerListAdapter drawerAdapter = new DrawerListAdapter(this, mNavItems);
mDrawerList.setAdapter(drawerAdapter);
mDrawerList.setFitsSystemWindows(true);
// Drawer Item click listeners
mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItemFromDrawer(position);
}
});
我的xml文件代码:
<!-- The navigation drawer -->
<RelativeLayout
android:layout_width="280dp"
android:layout_height="match_parent"
android:id="@+id/drawerPane"
android:fitsSystemWindows="true"
android:layout_gravity="start">
<!-- Profile Box -->
<RelativeLayout
android:id="@+id/profileBox"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/colorPrimary"
android:padding="8dp" >
<ImageView
android:id="@+id/avatar"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/user"
android:clickable="false"
android:layout_marginTop="15dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/avatar"
android:orientation="vertical" >
<TextView
android:id="@+id/userName_hamburger"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome"
android:textColor="#fff"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/view_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginTop="4dp"
android:text="View Profile"
android:clickable="true"
android:textColor="#fff"
android:textSize="12sp" />
</LinearLayout>
</RelativeLayout>
<!-- List of Actions (pages) -->
<ListView
android:id="@+id/navList"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_below="@+id/profileBox"
android:choiceMode="singleChoice"
android:background="#ffffffff" />
</RelativeLayout>
我的活动xml文件:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true"
tools:context=".ui.DriverScreenActivity">
<android.support.design.widget.AppBarLayout android:layout_width="match_parent"
android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"/>
<include layout="@layout/content_customer_screen" />
<android.support.design.widget.FloatingActionButton android:id="@+id/logout"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="160sp"
android:scaleType="fitXY"
android:src="@drawable/btn_logout" />
</android.support.design.widget.CoordinatorLayout>