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?
Use Following Constructor to create Button Object:
http://developer.android.com/reference/android/widget/Button.html#Button(android.content.Context, android.util.AttributeSet, int)
public Button (Context context, AttributeSet attrs, int defStyle)
and pass following parameters:
Button btn = new Button (m_context, null, R.style.Button_Plain);
No need to use XmlPullParser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With