How to dynamically create a button and assign it a style defined in styles.xml?

Viewed 5206

I need to dynamically create a styled button. I thought maybe I should do it like this:

XmlPullParser parser = m_context.getResources().getXml(R.style.Button_Plain);
buttonStyle = Xml.asAttributeSet(parser);
Button btn = new Button (m_context, buttonStyle);

But getXml throws exception "Requesting resource failed because it is complex". Is there any easy way to do what I need?

2 Answers
Related