Skip to content

Instantly share code, notes, and snippets.

@benjaminVadon
Last active September 2, 2015 14:01
Show Gist options
  • Save benjaminVadon/bd577240e6b97d8d3bd1 to your computer and use it in GitHub Desktop.
Save benjaminVadon/bd577240e6b97d8d3bd1 to your computer and use it in GitHub Desktop.
package com.support.android.designlibdemo;
import android.content.Context;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;
import android.view.ViewParent;
public class CTLCompatToolbar extends Toolbar {
private boolean isParentCTL;
public CTLCompatToolbar(Context context) {
super(context);
}
public CTLCompatToolbar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CTLCompatToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void setTitle(CharSequence title) {
ViewParent parent = getParent();
if(shouldCTLInterceptTitle(parent)) {
((CollapsingToolbarLayout)parent).setTitle(title);
}else {
super.setTitle(title);
}
}
private boolean shouldCTLInterceptTitle(ViewParent parent) {
if(isParentCTL(parent)){
isParentCTL = true;
}
return isParentCTL;
}
private boolean isParentCTL(ViewParent parent) {
return parent!=null && (isParentCTL || parent instanceof CollapsingToolbarLayout);
}
}
@benjaminVadon
Copy link
Author

and cheesquare change to :

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(cheeseName);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment