1

i can set a style like this

ImageView
android:id="@+id/blah"
style="@style/mystyle"
/>

But Is there a way to set a style for a View at runtime? Like

ImageView iv = (ImageView)findViewById(...);
iv.setStyle(R.style.myotherstyle); 
Youddh
  • 1,511
  • 4
  • 34
  • 51

2 Answers2

2

There is no setStyle() method because you can't change the style after the view is initialized.


Check this : Where is the View.setStyle() method?

Imran Rana
  • 11,899
  • 7
  • 45
  • 51
1

No, unfortunately there is no way to change a style at runtime. Your best bet is to set the individual attributes (padding/margins/width/etc) one at a time at runtime.

Cathal Comerford
  • 1,020
  • 1
  • 9
  • 12
  • or else if you got only 2 styles then make the imageView with these 2 styles and make 1 of them invisible at compile time and make it visible at runtime(the previous 1 is made invisible). any layout related thing is better done at compile time. – Housefly Jun 11 '12 at 11:46