How to implement android Toolbar Back button

后端 未结 6 975
野性不改
野性不改 2021-01-03 23:37

I am using a custom toolbar. I need to add back button to it. Now I am using this code to add the back button.

Toolbar toolbar = (Toolbar) getActivity().find         


        
6条回答
  •  执笔经年
    2021-01-04 00:19

    use Method in Class your Activity

    private void setupToolbar(){
      Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar);
           setSupportActionBar(toolbar);
           ActionBar actionBar=getSupportActionBar();
           actionBar.setDisplayHomeAsUpEnabled(true);
           actionBar.setDisplayShowHomeEnabled(true);
           toolbar.setNavigationOnClickListener(new View.OnClickListener() {
       @Override
              public void onClick(View v) {  
               finish();  
                 }
                   });
                  }
    

提交回复
热议问题