How to set the Toolbar collapseIcon color programmatically

为君一笑 提交于 2019-12-01 06:13:15

Finally got it...

This is what worked for me:

final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
AppBarLayout appBar = (AppBarLayout) findViewById(R.id.appbar);
appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        for (int i = 0; i < toolbar.getChildCount(); i++) {
            View view = toolbar.getChildAt(i);
            if (view instanceof ImageButton) {
                ImageButton btn = (ImageButton) view;
                Drawable drawable = btn.getDrawable();
                drawable.setColorFilter(new_button_color, PorterDuff.Mode.SRC_ATOP);
                btn.setImageDrawable(drawable);
            }
        }
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!