When toolbar back button is pressed

后端 未结 4 1476
梦谈多话
梦谈多话 2021-01-28 00:01

how can I create a condition on my android app where When I pressed the back button on the toolbar some code will happening.

I tried this but it doesnt work.

<         


        
4条回答
  •  心在旅途
    2021-01-28 00:39

    Toolbar manipulations.

            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            // Title and subtitle
            toolbar.setTitle(R.string.about_toolbar_title);
            toolbar.setSubtitleTextColor(Color.WHITE);
            toolbar.setTitleTextColor(Color.WHITE);
            toolbar.setBackgroundColor(getResources().getColor(
                    R.color.themeToolbarColor));
            toolbar.setNavigationIcon(R.drawable.ic_action_back);
            toolbar.setNavigationOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
    

提交回复
热议问题