我用这段代码在我的棒棒糖设备中更改了我的工具栏。
toolbar.setBackgroundColor(
ContextCompat.getColor(getApplicationContext(), R.color.colorWhite));
但是当我尝试在 API19 中使用我的应用程序时。
工具栏颜色不会更改。
试试
int color = getApplicationContext().getResources().getColor(R.color.colorWhite);
toolbar.setBackgroundColor(color);
setSupportActionBar(toolbar)
编辑:由于 API 已更改并且现在发生了降级,因此我会建议一些东西 lke
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.MARSHMALLOW){
//set using depricated code [one i put earlier]
}else{
//set using latest api;s [ones which youre currently using]
}