“Back button” using getSupportActionbar and appcompat v7 toolbar

前端 未结 8 609
时光取名叫无心
时光取名叫无心 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 02:52

    Simply you can set Navigation icon and make sure you are setting setNavigationOnClickListener() after setting setSupportActionBar(toolbar)

    toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back));
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    

提交回复
热议问题