简体   繁体   中英

How to make back button on action bar clickable

i succeeded in adding a back button to the action bar of an activity but when clicked nothing happens here is the code

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_fullscreen);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

all i want to know is how to make the button clickable (to go back) thanks.

First of all you should ask Google, it's your friend. Questions like that will be mark down and probably closed like duplicate.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            //do what you want
            onBackPressed();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM