工具栏背景、文字、箭头和三点弹出菜单颜色。
1) 背景:
toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.toolbar_color));
或(需要 API 16):
toolbar.setBackground(new ColorDrawable(ContextCompat.getColor(this, R.color.toolbar_color)));
2) 标题:
toolbar.setTitleTextColor(ContextCompat.getColor(this, R.color.gray);
3) 箭头:
toolbar.getNavigationIcon().setColorFilter(ContextCompat.getColor(this, R.color.gray), PorterDuff.Mode.SRC_ATOP);
4) 弹出菜单三点图标(右侧图标):
toolbar.getOverflowIcon().setColorFilter(ContextCompat.getColor(this, R.color.gray, PorterDuff.Mode.SRC_ATOP);
请参阅 https://stackoverflow.com/a/26837072/2914140 和 https://stackoverflow.com/a/51908890/2914140。
多合一(在 Kotlin 中):
toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.blue))
val toolbarTextColor = ContextCompat.getColor(this, R.color.gray)
toolbar.setTitleTextColor(toolbarTextColor)
toolbar.navigationIcon?.setColorFilter(toolbarTextColor, PorterDuff.Mode.SRC_ATOP)
toolbar.overflowIcon?.setColorFilter(toolbarTextColor, PorterDuff.Mode.SRC_ATOP)