Suppose we have a TextView as
TextView text = (TextView) activity.findViewById(R.id.text);
1. Set Background Color Programmatically
text.setBackgroundColor(Color.LTGRAY);
2. Get Background Color Programmatically
(ColorDrawable)text.getBackground()).getColor();