I wanted to set the background color of my Navigation drawer in java but it seems as setBackgroundColor and all similar methods have no effect. Only the XML line
setBackgroundColor
cast your navigation drawer to navigationView and do as follows
navigationView.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));