Skip to content

Instantly share code, notes, and snippets.

@eoinahern
Created June 15, 2018 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eoinahern/6432ce1db9cc716dbad20446e1739552 to your computer and use it in GitHub Desktop.
Save eoinahern/6432ce1db9cc716dbad20446e1739552 to your computer and use it in GitHub Desktop.
//back navigation in android
//initate toolbar
val detailsToolbar: Toolbar by lazy { findViewById<Toolbar>(R.id.toolbar) }
//in onCreate
this.setSupportActionBar(detailsToolbar)
actionBar = supportActionBar
actionBar?.apply {
this.setDisplayHomeAsUpEnabled(true)
this.setHomeButtonEnabled(true)
this.setHomeAsUpIndicator(R.drawable.ic_back_dark)
}
// onOptionsItemSelected
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
android.R.id.home -> {
this.finish()
true
}
else -> super.onOptionsItemSelected(item)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment