0

How to GET Layout's background color ?

For example i have a MainActivity and FormOne.xml and FormTwo.xml as layout. Now i want to GET background color of FormTwo.xml in MainActivity...

Is it possible? and how

Thanks in advance.

Yousha Aleayoub
  • 4,532
  • 4
  • 53
  • 64

1 Answers1

2

As you can find th answer in another question (Android: How to get background color of Activity in Java?).

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();
Community
  • 1
  • 1
  • 1
    Thanks, but what about getting background's color of a ANOTHER activity/layout? Ex. FORM2.xml ? – Yousha Aleayoub Sep 20 '14 at 12:06
  • 1
    Just a guess, but it can work: A bit hax, but maybe you can inflate the layout and then get the background of the activity. Later you can override the inflated view. I cannot try it atm, I don't have working adt on my pc, and have several other things to do. If it isn't working, I'm sorry, but i dont have anything else in my mind. – Zoltán Dudás Sep 20 '14 at 20:53