Last active
September 2, 2015 14:01
-
-
Save benjaminVadon/bd577240e6b97d8d3bd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and cheesquare change to :