So originally I was following this tutorial on creating a custom navigation drawer: http://www.tutecentral.com/android-custom-navigation-drawer/.
But since I want to use a BaseActivity I modified it according to this SO post: creating base activity with navigation drawer in android.
However, when I click the button that should trigger the drawer the logs show activity:
[0,Home]
and
com.android.internal.view.menu.ActionMenuItem@1796f4d4
But no drawer is being opened and no error is thrown.
<!-- activity_base.xml -->
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
The (I guess) relevant pieces of my BaseActivity.java:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_base);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowHomeEnabled(false);
getActionBar().setHomeButtonEnabled(true);
if (savedInstanceState == null) {
displayView(0);
}
}
private class SlideMenuClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// display view for selected nav drawer item
displayView(position);
}
}
@Override
public void setContentView(int layoutResID) {
super.setContentView(layoutResID);
mDrawerLayout = (DrawerLayout) getLayoutInflater().inflate(R.layout.activity_base, null);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mContentFrame = (FrameLayout) mDrawerLayout.findViewById(R.id.content_frame);
getLayoutInflater().inflate(layoutResID, mContentFrame, true);
mTitle = mDrawerTitle = getTitle();
navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons);
navDrawerItems = new ArrayList<NavDrawerItem>();
navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
navMenuIcons.recycle();
mDrawerToggle = new ActionBarDrawerToggle(
this,
mDrawerLayout,
R.drawable.ic_drawer,
R.string.drawer_open,
R.string.drawer_close
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
System.out.println("CLOSED");
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
System.out.println("OPENED");
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
public void onDrawerStateChanged(int newState) {
System.out.println("STATUS: "+newState);
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
adapter = new NavDrawerListAdapter(getApplicationContext(), navDrawerItems);
mDrawerList.setAdapter(adapter);
mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
}