To assign a style like this
<style name="ButtonHOLO" parent="android:Widget.Button"> <item name="android:background">@drawable/btn_default_holo_dark</item> <item name="android:minHeight">@dimen/calc_btn_h</item> <item name="android:minWidth">@dimen/calc_btn_w</item> <item name="android:textColor">#ffffff</item> </style>
the button dynamically needs to use the setBackgroundResource () and setTextAppearance () functions. For example:.
btn.setBackgroundResource(R.drawable.btn_default_holo_dark); btn.setTextAppearance(context, R.style.ButtonHOLO);
Where
btn_default_holo_dark
is the name of the .xml file that describes the selector for your button.
TrickOrTreat
source share