How can I get background color and text color (default for child views) of an Activity in Java?
Asked
Active
Viewed 1.2k times
2 Answers
35
TypedArray array = getTheme().obtainStyledAttributes(new int[] {
android.R.attr.colorBackground,
android.R.attr.textColorPrimary,
});
int backgroundColor = array.getColor(0, 0xFF00FF);
int textColor = array.getColor(1, 0xFF00FF);
array.recycle();

jzavisek
- 665
- 6
- 6
-
Thank you so much. – arc May 24 '16 at 19:17
1
For Background
TypedArray array = context.getTheme().obtainStyledAttributes(new int[] {
android.R.attr.windowBackground});
int backgroundColor = array.getColor(0, 0xFF00FF);
array.recycle();
view.setBackgroundColor(backgroundColor);

Javier
- 1,469
- 2
- 20
- 38