Menu-item to show a navigationdrawer and a back arrow to return
Clash Royale CLAN TAG#URR8PPP
Menu-item to show a navigationdrawer and a back arrow to return
I want that the back icon in the toolbar is on the left side and it returns to the previous page. And the menu icon in the toolbar should be on the right side and to show the navigationdrawer.
I already have:
My code:
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar=(android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
//drawerlayout
mDrawerLayout=(DrawerLayout) findViewById(R.id.activity_main3);
ActionBarDrawerToggle mToggle=new ActionBarDrawerToggle(this,mDrawerLayout,mToolbar,R.string.open,R.string.close);
mDrawerLayout.addDrawerListener(mToggle);
mToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle("NOSTRILS");
1 Answer
1
Solved the issue by making a lot of changes to code:
public class MainActivity extends AppCompatActivity
private DrawerLayout drawerLayout;
private Toolbar toolbar;
private EndDrawerToggle drawerToggle;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
/* Toolbar */
getSupportActionBar().setTitle("Nostrils");
toolbar.setTitleTextColor(0xFFFFFFFF);
// Back icon
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
initNavigationDrawer();
drawerLayout = (DrawerLayout)findViewById(R.id.activity_main3);
drawerToggle = new EndDrawerToggle(this,
drawerLayout,
toolbar,
R.string.open,
R.string.close);
drawerLayout.addDrawerListener(drawerToggle);
@Override
protected void onPostCreate(Bundle savedInstanceState)
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
@Override
public boolean onOptionsItemSelected(MenuItem item)
// Handle action bar item clicks here.
int id = item.getItemId();
// Back icon clicked
Intent i = new Intent(MainActivity.this, Main2Activity.class);
startActivity(i);
finish();
return super.onOptionsItemSelected(item);
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.