I'm trying to using fragment layout and navigation drawer for menu option, but I'm getting error:
java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.support.v7.widget.Toolbar
My java file:
My fragment file:
I'm trying to using fragment layout and navigation drawer for menu option, but I'm getting error:
java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.support.v7.widget.Toolbar
My java file:
My fragment file:
give id in your xml fragment like android:id="@+id/fragment_drawer"
mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_drawer);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close) {
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
};
// Set up the drawer.
mNavigationDrawerFragment.setUp(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer));
Comment this line and run it:
mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);//this is wrong casting
I recomend you that please remove the following code from Your Java code and the try to Build the project
mtoolbar = (ToolBar) findviewById(R.id.mtoolbar);
You Dont need add action bar separately....!