Add back button to action bar

后端 未结 11 1692
野趣味
野趣味 2020-12-07 16:23

I have been trying to add a back button to the action bar.

I want my view to look like this: \"enter

11条回答
  •  -上瘾入骨i
    2020-12-07 16:53

    this one worked for me:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_your_activity);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        // ... other stuff
    }
    
    @Override
    public boolean onSupportNavigateUp(){
        finish();
        return true;
    }
    

    The method onSupportNavigateUp() is called when you use the back button in the SupportActionBar.

提交回复
热议问题