xxxxxxxxxx
import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// calling the action bar
var actionBar = getSupportActionBar()
if (actionBar != null) {
// Customize the back button
actionBar.setHomeAsUpIndicator(R.drawable.mybutton);
// showing the back button in action bar
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
// this event will enable the back
// function to the button on press
override fun onContextItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
android.R.id.home -> {
finish()
return true
}
}
return super.onContextItemSelected(item)
}
}
xxxxxxxxxx
getSupportActionBar().setDisplayHomeAsUpEnabled(true);getSupportActionBar().setDisplayShowHomeEnabled(true);
xxxxxxxxxx
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);setSupportActionBar(toolbar);