As per the design rule is it really a good idea to introduce a back button for Activity in Android?
I believe every device, now a days, or running Android OS has a hardware back button.
What is your suggestion on implementing software back button?
How can I enable it, if at all hardware back button support is not present?
答案 0 :(得分:2)
@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);
}
希望它可以帮到你!
答案 1 :(得分:1)
There are new way for going back is home button of Toolbar.you can enable home button in your toolbar(actionbar) for go to back.
答案 2 :(得分:1)
Lollipop introduced a new software back button in the Action Bar. You should read all docs about Material design
To navigate back from an activity, just call
finish()
Read some info on the back stack, as this is key to navigate using both activities and fragments