15

How can I get background color and text color (default for child views) of an Activity in Java?

TN.
  • 18,874
  • 30
  • 99
  • 157

2 Answers2

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
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