Created
November 19, 2016 12:04
-
-
Save mahdimortazavi/18fc34cfa3fd615cd098a5141ac11fe7 to your computer and use it in GitHub Desktop.
change back arrow color dynamically
This file contains hidden or 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
public abstract class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener { | |
public enum State { | |
EXPANDED, | |
COLLAPSED, | |
IDLE | |
} | |
private State mCurrentState = State.IDLE; | |
@Override | |
public final void onOffsetChanged(AppBarLayout appBarLayout, int i) { | |
if (i == 0) { | |
if (mCurrentState != State.EXPANDED) { | |
onStateChanged(appBarLayout, State.EXPANDED); | |
} | |
mCurrentState = State.EXPANDED; | |
} else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) { | |
if (mCurrentState != State.COLLAPSED) { | |
onStateChanged(appBarLayout, State.COLLAPSED); | |
} | |
mCurrentState = State.COLLAPSED; | |
} else { | |
if (mCurrentState != State.IDLE) { | |
onStateChanged(appBarLayout, State.IDLE); | |
} | |
mCurrentState = State.IDLE; | |
} | |
} | |
public abstract void onStateChanged(AppBarLayout appBarLayout, State state); | |
} |
This file contains hidden or 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
AppBarLayout appBarLayout=(AppBarLayout)findViewById(R.id.app_bar_layout); | |
appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { | |
@Override | |
public void onStateChanged(AppBarLayout appBarLayout, State state) { | |
Log.i("mahdiTag", state.name()); | |
if(state.name().equals("COLLAPSED")){ | |
CustomToolbar.colorizeToolbar(toolbar, getResources().getColor(R.color.white), PlacesActivity.this); | |
}else if (state.name().equals("EXPANDED")){ | |
CustomToolbar.colorizeToolbar(toolbar, getResources().getColor(R.color.black), PlacesActivity.this); | |
}else if (state.name().equals("IDLE")){ | |
CustomToolbar.colorizeToolbar(toolbar, getResources().getColor(R.color.grey), PlacesActivity.this); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment