Soft Back Button for Android Activity
As a design rule, is it really a good idea to introduce a back button for Android Activity?
I believe that every device, now the other day or on the Android operating system, has a hardware return button.
What is your proposal for implementing a software return button?
How can I enable it if there is no back button support at all?
+3
source to share
3 answers
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//enable soft back button
ActionBar ab =getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(true);
}
//handle click event
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id==android.R.id.home){
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
Hope this helps you!
+2
source to share
Lollipop introduced a new software return button in the action bar. You must read all documents about Material Design
To get back to action, just call
finish()
Read the back stack information as this is the key to navigate using both actions and fragments
+1
source to share