“Back button” using getSupportActionbar and appcompat v7 toolbar

前端 未结 8 590
时光取名叫无心
时光取名叫无心 2021-01-30 02:27

I\'m using the new toolbar from the Appcompat V7 library and I\'m making an application with navigation drawer and with fragments.

In some fragments I don\'t want to sho

8条回答
  •  走了就别回头了
    2021-01-30 02:50

    Add setDisplayHomeAsUpEnabled(true)

        Toolbar toolbar  = findViewById(R.id.toolbar);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    

    Handle the back button

       public boolean onSupportNavigateUp() {
        onBackPressed();
        return true;
    }
    

提交回复
热议问题