我已经从 Chris Banes 示例代码中实现了新的 CollapsingToolbarLayout
。
但是,背景 ImageView 的图像都是白色背景。工具栏主题是 ThemeOverlay.AppCompat.Dark.ActionBar
所以图标也是白色的,所以当 CollapsingToolbarLayout 完全展开时我看不到主页按钮。
使用 app:expandedTitleTextAppearance
我可以设置标题字段的颜色。是否也可以设置主页按钮和菜单图标的颜色?
最佳答案
这是我如何在布局展开和折叠时更改抽屉和选项图标颜色的示例:
protected void onCreate(Bundle savedInstanceState) {
AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout);
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int offset)
{
Drawable upArrow = ResourcesCompat.getDrawable(getResources(), R.drawable.drawer_icon, null);
if (offset < -200)
{
upArrow.setColorFilter(Color.parseColor("#000000"), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
Drawable drawable = ContextCompat.getDrawable(getApplicationContext(),R.drawable.option_menu_icon);
drawable.setColorFilter(Color.parseColor("#000000"), PorterDuff.Mode.SRC_ATOP);
toolbar.setOverflowIcon(drawable);
}
else
{
upArrow.setColorFilter(Color.parseColor("#ffffff"), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Drawable drawable = ContextCompat.getDrawable(getApplicationContext(),R.drawable.option_menu_icon);
drawable.setColorFilter(Color.parseColor("#ffffff"), PorterDuff.Mode.SRC_ATOP);
toolbar.setOverflowIcon(drawable);
}
}
});
关于android - CollapsingToolbarLayout : Change home button color when expanded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30936373/