Disable CollapsingToolbarLayout
<p>my application provide different contents, some of them is with image and others not.
For those which have image i am using CollapsingToolbarLayout it works fine but for those which have not image I want collapse CollapsingToolbarLayout and prevent expanding, disable it.</p>

<p>Here is my item activity code:</p>

<pre><code>public class ItemActivity extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_item);

        collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
        collapsingToolbar.setStatusBarScrimResource(R.color.black_transparent_190);
        collapsingToolbar.setContentScrimResource(R.color.gray_transparent_150);
        collapsingToolbar.setExpandedTitleTextAppearance(R.style.MyTheme_Toolbar_Title_Expanded);

        appBarLayout = (AppBarLayout) findViewById(R.id.appbar);
        appBarLayout.setExpanded(false);
        loadData();
    }

    public void loadData() {
        if(haveImage) {
          // loading data and image
          appBarLayout.setExpanded(true, true);
        } else {
          appBarLayout.setExpanded(false);
        }
    }
}
</code></pre>

<p>I have already tried</p>

<pre><code>AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) collapsingToolbar.getLayoutParams();
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
collapsingToolbar.setLayoutParams(params);
</code></pre>

<p>and</p>

<pre><code>CollapsingToolbarLayout.LayoutParams mParams = new CollapsingToolbarLayout.LayoutParams(collapsingToolbar.getLayoutParams());
mParams.setCollapseMode(CollapsingToolbarLayout.LayoutParams.COLLAPSE_MODE_OFF);
mToolbar.setLayoutParams(mParams);
</code></pre>

<p>It works, it's prevent collapsing!
<strong>But collapsing toolbar is expanded!</strong></p>

<p>How can I collapse toolbar and disable it for scrolling events?</p>