app/src/main/java/com/obadajasem/blablabla/MainActivity.java
private void initCollapsingToolbar() {
        final CollapsingToolbarLayout collapsingToolbar = findViewById(R.id.collapsing_toolbar);
        collapsingToolbar.setTitle(" ");
        AppBarLayout appBarLayout = findViewById(R.id.appbar);
        appBarLayout.setExpanded(true);

        // hiding & showing the title when toolbar expanded & collapsed
        appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            boolean isShow = false;
            int scrollRange = -1;

            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                if (scrollRange == -1) {
                    scrollRange = appBarLayout.getTotalScrollRange();
                }
                if (scrollRange + verticalOffset == 0) {
                    collapsingToolbar.setTitle(getString(R.string.app_name));
//                    showOption(R.id.action_info);
                    isShow = true;
                } else if (isShow) {

                    collapsingToolbar.setTitle(" ");
//                    hideOption(R.id.action_info);
                    isShow = false;
                }
            }
        });
    }
/**
     * Initializing collapsing toolbar
     * Will show and hide the toolbar title on scroll
     */
Initializing collapsing toolbar
Will show and hide the toolbar title on scroll
Initializing collapsing toolbar Will show and hide the toolbar title on scroll
private void initCollapsingToolbar() {
        final CollapsingToolbarLayout collapsingToolbar = findViewById(R.id.collapsing_toolbar);
        collapsingToolbar.setTitle(" ");
        AppBarLayout appBarLayout = findViewById(R.id.appbar);
        appBarLayout.setExpanded(true);
        appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            boolean isShow = false;
            int scrollRange = -1;
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                if (scrollRange == -1) {
                    scrollRange = appBarLayout.getTotalScrollRange();
                }
                if (scrollRange + verticalOffset == 0) {
                    collapsingToolbar.setTitle(getString(R.string.app_name));
                    isShow = true;
                } else if (isShow) {
                    collapsingToolbar.setTitle(" ");
                    isShow = false;
                }
            }
        });
    }
private void initCollapsingToolbar ( ) { final CollapsingToolbarLayout collapsingToolbar = findViewById ( R . id . collapsing_toolbar ) ; collapsingToolbar . setTitle ( " " ) ; AppBarLayout appBarLayout = findViewById ( R . id . appbar ) ; appBarLayout . setExpanded ( true ) ; appBarLayout . addOnOffsetChangedListener ( new AppBarLayout . OnOffsetChangedListener ( ) { boolean isShow = false ; int scrollRange = - 1 ; @ Override public void onOffsetChanged ( AppBarLayout appBarLayout , int verticalOffset ) { if ( scrollRange == - 1 ) { scrollRange = appBarLayout . getTotalScrollRange ( ) ; } if ( scrollRange + verticalOffset == 0 ) { collapsingToolbar . setTitle ( getString ( R . string . app_name ) ) ; isShow = true ; } else if ( isShow ) { collapsingToolbar . setTitle ( " " ) ; isShow = false ; } } } ) ; }
Initializing collapsing toolbar
 Will show and hide the toolbar title on scroll
Initializing collapsing toolbar Will show and hide the toolbar title on scroll
// hiding & showing the title when toolbar expanded & collapsed //                    showOption(R.id.action_info); //                    hideOption(R.id.action_info);