How to change the Style of a button dynamically in android?

By | March 23, 2013

Here I am going to change the style of a default button to buttonStyleSmall. So after that the button will appear small.

this simple code does this.

Button myButton = new Button(context, null, android.R.attr.buttonStyleSmall);

The try this adding to a layout

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                                     RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(android.widget.RelativeLayout.ALIGN_PARENT_RIGHT);
rLayout.addView(rightButton, lp);

Leave a Reply

Your email address will not be published. Required fields are marked *