@Override public void onBackPressed() { if (!morphyToolbar.isCollapsed()) { hideFab(); morphyToolbar.collapse(); } else super.onBackPressed(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); primary2 = getResources().getColor(R.color.primary2); primaryDark2 = getResources().getColor(R.color.primary_dark2); appBarLayout = (AppBarLayout) findViewById(R.id.layout_app_bar); toolbar = (Toolbar) findViewById(R.id.toolbar); fabPhoto = (FloatingActionButton) findViewById(R.id.fab_photo); disableAppBarDrag(); hideFab(); morphyToolbar = MorphyToolbar.builder(this, toolbar) .withToolbarAsSupportActionBar() .withTitle("Work [not so] serious talk") .withSubtitle("160 participants") .withPicture(R.drawable.img_profile) .withHidePictureWhenCollapsed(false) .build(); morphyToolbar.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (morphyToolbar.isCollapsed()) { morphyToolbar.expand( primary2, primaryDark2, new MorphyToolbar.OnMorphyToolbarExpandedListener() { @Override public void onMorphyToolbarExpanded() { showFab(); } }); } else { hideFab(); morphyToolbar.collapse(); } } }); if (getSupportActionBar() != null) { getSupportActionBar() .setDisplayOptions( ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } }