Very interesting, did you try to add another view instead as setContentView(LinearLayout) and after add TextView to parent.
Or it is because Attributes are null. On 27 Лис, 22:26, poohtbear <eyaltg...@gmail.com> wrote: > I was suggested to try using the last parameter of the View's C'tor > with my style, it doesn't work though. > Can anyone explain to me why the following doesn't work for me ? > 1. my Activity on Create: > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > TextView tv = new TextView(this, null, R.style.my_style_2); > tv.setText("this should be green!"); > setContentView(tv); > } > 2. bb.xml that contains the style: > <?xml version="1.0" encoding="utf-8"?> > <resources> > <style name="my_style_2"> > <item name="android:textColor">#FF00FF00</item> > <item name="android:textSize">20sp</item> > </style> > </resources> > > As far as i understand my text should be big (20 sp) and green. but > it's not... the styl is ignored. > I know that when android itself inflates the view the AttributeSet > allready contains the style even if style= attribute was used. > So how am i suppose to do it programatically ,what am i doing wrong ? > > On Nov 27, 6:06 pm, poohtbear <eyaltg...@gmail.com> wrote: > > > > > > > > > Hi. > > I want to create a View using code, not xml, but i do want to apply an > > xml style o it, so at least it's partially managed in xml. > > I thought the right way to do that would be tm get the style as an xml > > using the PullParserand then transform it to Attribute set that i can > > pass on to the View in the Ctor. > > > I can't find any proper Resources() method to get me a style xml as a > > pull Parser. > > I guess i can try to dig deeper as forhow it's parsed when a style= > > appears in a layout xml, but i was hoping for a faster answer here. > > > 10x. > > Eyal. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en